Making a Car

From VR Wiki
Revision as of 04:53, 30 September 2022 by N3X15 (talk | contribs) (→‎Vroom)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

ChilloutVR allows one to make realistically-behaving vehicles as props. This is a guide will teach you how to produce a working vehicle using Realistic Car Controller.

Prerequisites

Model Setup

This part of the guide is not going to be step-by-step, because models can be complex and the changes between Blender versions and different modelling software can introduce vast changes in workflow. Instead, this guide will outline what your model needs to have in order to work properly with RCC.

  • Wheels must be separated into submeshes or armature bones. It's recommended to name them something like FrontLeft/FrontRight/BackLeft/BackRight, but any name will work.
  • Wheels must have their rotation axis aligned along the X axis, and the origin somewhere along the rotation axis.
  • At least four wheels are required.
  • The origin of the body should be at 0,0,0, with the bottom of the wheels at 0 Y.
  • Steering Wheel is optional, rotation aligned along Z, with the up direction being -Z.
  • It's recommended to have separated seat meshes to use as interactable seat positions.
  • It's recommended to make a custom body collision mesh that does not include wheels or suspension.

Once your origins and axes are set properly, you need to move the submeshes (and only the submeshes) into the correct positions in the car.

Unity Editor Setup

Warning: It is HIGHLY RECOMMENDED to make a separate project for vehicles, as RCC requires a weird environment. While it can work with other props and avatars, some shaders and editor packages can throw errors in an RCC project due to input changes.

Creating the Project

  1. Open Unity Hub.
  2. Install Unity 2019.4.31f1 from the LTS release page (or whatever version CVR currently requires).
  3. In the Unity Hub, click the Create Project button.
  4. At the top of the screen, make sure the Editor Version is set to the correct version (2019.4.31f1 at time of writing).
  5. Select the 3D: Core project template.
  6. Name the project something appropriate.
  7. Set the location to somewhere on a drive with plenty of empty space (>5GB). For example, I usually put all my CVR-related projects in V:\CVR.
  8. Click "Create Project."

Preparation

  1. Install the CCK.
  2. Open Edit > Project Settings.
  3. Select the Player tab from the list on the right side of the dialog.
  4. Scroll down until you see Other Settings. Expand it, if needed.
  5. Under the Configuration heading, change Active Input Handling to Both.
  6. When Unity asks to restart the editor, do so.

Importing RCC

  1. Buy Realistic Car Controller (by Bonecracker Games) from the Unity Asset Store.
    • It's not recommended to pirate RCC, as the UnityPackages pirates offer often do not change project settings, or are old and/or broken. Just save yourself the grief and buy the damn thing.
  2. In the Editor, select Window > Asset Store (or press Ctrl+9).
  3. Log in, if needed.
  4. Go to My Assets.
  5. Find Realistic Car Controller in the list.
  6. If the Download button is shown next to RCC, press it and wait for it to download.
  7. Press the Import Button next to RCC.
  8. When Unity tells you it has Package Manager dependencies, select Install/Upgrade.
  9. Click Import once the Import Unity Package dialog appears. Do not unselect anything.
  10. Unity will tell you it found some missing layers. Press Add.

Vroom

This part will be less specific due to differing model workflows and needs.

Importing

  1. Close Unity so it doesn't reimport everything 15 times while you copy everything over.
  2. Save your model to some subfolder of Assets. I generally use something like Assets\Vehicles\VEHICLENAME\models\vehiclename.fbx.
  3. Save your textures to another subfolder of Assets. I generally use something like Assets\Vehicles\VEHICLENAME\textures\SKINNAME\*.png.
  4. Open Unity.
  5. Wait for the import to finish.
  6. Import your favorite shaders, if needed.
    • Do not use Standard, as many maps still assume everyone uses toon shaders and therefore don't have reflection probes and/or lighting probes. If you need something standard-y, use Rero Standard, as it permits faked lighting and fallback cubemaps.

The Scene

First, we need a ground plane so your car doesn't fall through the world when you upload it.

  1. GameObject > 3D Object > Plane
  2. Rename to "Ground Plane" or something.
  3. Change Y position of the ground plane to -0.01 or something.

Making a Prop

Now import your car and set it up as a prop. Do not add any interactables, pickups, etc.

  1. Drag the FBX/OBJ/STL/etc model into the scene.
  2. Click on the root of the vehicle in the hierarchy.
  3. Add a CVR Spawnable component.
  4. Check "Enable Sync Values."
  5. Press the button under "Sub Sync Transforms" five times (one for each wheel, plus the steering wheel).
  6. Drag the steering wheel into the first "Transform" box.
  7. Change Synced Properties to Everything.
  8. Change Sync Precision to Full.
  9. Select your car's root in the scene.
  10. Create an empty GameObject called "COM" and move it to the general position of your car's Center of Mass.
  11. Do the same for each wheel.

Body Collider

Your car needs to have a body collider so it'll handle impacts properly, among other things.

There are two choices here: mesh colliders and a capsule collider.

Mesh Collider

A mesh collider is:

  • Complicated
  • A pain in the ass to make and configure

BUT:

  • Accurate
  • Tailored to the car in question

To make one:

TODO: Words

Capsule Collider

A capsule collider is:

  • Simple
  • Rounded at the top, so it'll roll the car back over when flipped
  • Rounded at the front, so ramps and small obstacles don't flip the car

BUT:

  • Inaccurate

To make one:

  1. Select the body of the car (or the root).
  2. Add Component
  3. Select Capsule Collider
  4. Change Direction to Z-axis (or X-axis, whichever direction your car faces).
  5. Press the button.
  6. Change the scene to isometric mode.
  7. Change to the side view.
  8. Move and resize the capsule until it roughly fits ONLY THE BODY of the car, and any rollbars. Precision is not important. The bottom of the collider must NOT touch the ground.
  9. Change to the front or rear view and continue tweaking.
  10. Exit edit mode by hitting the Edit Collider button again.
  11. Exit isom mode.
Side view

RCC Controller

  1. Completely unpack your car prefab in the scene. Yes, this is required.
  2. Select the car's root again.
  3. Select Tools > Bonecracker Games > Realistic Car Controller > Add Main Controller to Vehicle. This will add RCC as well as the Rigidbody used for physics.
  4. If your pivot point is fucked, allow RCC to fix it. The tear-drop shaped thing is your pivot.
  5. Wheels button
    Click the tire in the RCC controller. (first button)
  6. Drag all of your wheels into the given slots.
  7. Generate colliders. Use Center position when asked.
  8. Drag your steering wheel into the steering wheel slot and set the axis to Z.
  9. Click on the last big menu button (Damage and Repair).
  10. Uncheck Use Damage, Use Collision Particles, and Use Collision Audio.

Now for the hard part.

The Hard Part

  1. Find and click on the thing you want to work as the button to sit down. Generally, this would be the car seat, steering wheel, or even the root of the car.
  2. Create a CVRInteractable inside of this gameobject.
  3. Add Trigger.
  4. Set Trigger to On Interact Down.
  5. Change Broadcast Type to Local Not Networked.
  6. Change Distance to 2 or 3, depending on the size of your car.
  7. Add Action.
  8. Change Action Type to Sit At Position.
  9. Inside your car's body, create an empty GameObject called "Sitting".
  10. Drag "Sitting" into the Sitting Location box.
  11. Create another GameObject called "Exit".
  12. Drag "Exit" into the Exit Location box.
  13. Adjust "Sitting" until the spectral blue man looks like he's sitting in the driver's seat.
  14. Adjust "Exit" until the arrow is outside of the car on the ground, pointed at the car.
  15. Check Lock Controls.
  16. In On Enter Seat ():
  17. Add Runtime Only, car root, set RigidBody.isKinematic to true:
    1. Select Runtime Only from the first dropdown.
    2. Drag the root of the car into the "None (object)" box. (Selects the object we want to screw with.)
    3. Select Rigidbody > isKinematic from the second dropdown (Selects the component property to screw with).
    4. Check the checkbox (set the property value to true).
  18. Add Runtime Only, car root, set RCC_CarControllerV3.enabled property to true.
  19. Add Runtime Only, car root, call RCC_CarControllerV3.SetCanControl method with true. (Same sequence to set it up, just different internally.)
  20. Add Runtime Only, car root, call RCC_CarControllerV3.StartEngine method. (It won't let you select a value, this is normal and fine.)
  21. We need to fix a problem where the engine will keep running when you exit the car.
    1. Create an empty GameObject in the root of the car called "All Audio Sources" (capitalization, spelling, and casing all matter)
    2. Create a new methodcall in the interactable's On Enter Seat ():
      1. Runtime Only.
      2. Drag "All Audio Sources" to the object selection box.
      3. GameObject > SetActive
      4. Check the checkbox.
  22. On Exit Seat ():
    1. Add Runtime Only, car root, set RigidBody.isKinematic to true.
    2. Add Runtime Only, car root, set RCC_CarControllerV3.enabled to false. (uncheck the checkbox)
    3. Add Runtime Only, car root, call RCC_CarControllerV3.SetCanControl with false.
    4. Add Runtime Only, car root, call RCC_CarControllerV3.KillEngine.
    5. Add Runtime Only, All Audio Sources, call GameObject.SetActive with false.

You can now upload the car and it should be usable.