wiki.sine.space | sinespace

Vehicles Tutorial

From wiki.sine.space
Revision as of 11:21, 7 May 2018 by HannahT25 (Talk | contribs)

Jump to: navigation, search

Creating your own Vehicle

Starting out

Creating the scene

Start with a new scene, we'll be using this to test the vehicle The example world here was built with World Machine, you can use Wold Machine to generate your own environment too.

The Modular Vehicle Component

Firstly we'll be using the Modular Vehicle Component. This sine editor component allows us to tweak and modify and a vast array of settings and functions that are relevant to how vehicles handle within sinespace. You'll be able to get most different types of vehicles operating using this component with none of your own scripting needed.

Ground Vehicle

The Buggy

We're now going to add our car body into the world. For this tutorial, we're using a buggy.

If you're building your own models and textures, remember the wheels will need to be separated from the main body and separate from eachother in order to provide steering animations The Modular Vehicle Component allows for steering movement independent of the body and the control of different settings for each wheel.

Add the Mesh Collider

Next we're going to add the Mesh collider to the Buggy, you can use other coliders if you wish, but for this tutorial, we'll be sticking to the Mesh. The Convex mesh is being used in this example for simplicity and processing speed.

Add Modular Vehicle Component

Note: This will auto add the Ridgedbody component too, this component you should be familiar with, it tells unity that the object is dynamic and is affected by the physics system.

Note: Drag and Mass in the RidgedBody component will be overridden by the settings in the Modular Vehicle Component

Settings to pay attention to in RidgedBody

• Use Gravity - This needs to be checked.

• Is Kinematic - This needs to be unchecked. Keeping this unchecked means that the vehicle won't interact with the world until the player is using it.

• Interpolate - Set this to Interpolate. This will spend some extra processing time to check physics between frames.

• Collision Detection - This needs to be set to Continuous or Continuous Dynamic

Setting the vehicle type

  • Core Forces aren’t needed for the Car vehicle type
  • Wheels settings are important for Cars
  • Up to 20 wheels are support at the moment, any more will be ignored

Wheel colliders Select a wheel on your vehicle and then create and Empty Child Object Then move the child to be under the main GameObject in the Hierarchy Do this for each wheel on your vehicle - Doing this by this method places the colliders we’re creating in roughly the right spots so we don’t have to do as much repositioning later Once we have all the new child objects created, select them all and add the Wheel Collider component to the Inspector You should now see green circles appearing in the Scene window, these represent how the physics engine will consider the wheels of the Car, the little sphere at the bottom is the contact point, this is where the collider expects to touch the ground.

In this example we’re going to have to adjust the bounds a bit - Note, this doesn’t need to be exact, getting as close as possible will look better though

Settings in the Wheel collider - Suspension Distance, this is how far the collider can travel up and down from it’s original position and is represented in scene as an orange bar - You can also adjust the suspension spring physics - We’re going to use the following settings o Mass: 20 o Radius: 0.42 o Wheel Dampening Rate: 0.25 o Suspension Distance: 0.3 o Force App Point Distance: 0 o Suspension Spring  Spring: 3500  Dampener: 4500 - You only need to setup 1 collider and the settings will copy across the rest

Back on the Body and Modular Vehicle Component - Attach one of the back Wheel mesh to Wheel Visual Transform under Wheels section in the Modular Vehicle Component - Expand Element0 to configure the first wheel - Attach the Collider to the Wheel Collider - Note the position information from the collider will be used to position the visual transform, so keep them aligned - Change the Mass of the Rigidbody Component to 1500

Setting some Torque values - For this example we’re going to set the forward torque to 800 and the backward torque to 300 - The force is in newton meters - Brake torque of 2000 and an idle brake of 500 o Idle brake is essentially the negative force applied if no keys are being pressed Wheel config - Set the wheel size, this is the number of wheels - Drag the other back wheel mesh and collider to the Wheel Transform and Collider slots - The settings from Element 0 will have automatically been applied to the subsequent ones - Expand Element 1 and attach the other back wheel

Now for the front wheels - We’ll be turning off Motor Power for the front two wheels - When attaching them to Element 2 and 3 untick Forward and Backward torque - These wheels will be used for turning o Tick steering o Enter the turn speed, this is how fast the wheels turn when a keyboard is being used to steer as the key is non-variable unlike a controller You will need to mirror the setting changes for both Element 2 & 3

Setting a seat route This will now the player where to sit, if one is not set, the player will just sit in the middle of the vehicle. - Create a new GameObject - Position it where you would like the player to sit - Name it Seat - Now drop the game Object into the Seat Root on the Modular Vehicle Component

Cameras Create a new Empty Child and attach a Cinemachine Virtual Camera Component - Set the Loot At Target to the buggy - Set Follow to the buggy

Now we’re going to add a Cinemachine brain to the Main Camera so we can preview the camera - Add the Cinemachine Brain Component to the Main Camera

Back to the GameObject Camera we created - Set the Aim to Composer

Now if you switch to the Game View, you’ll see the camera scope, the black box is the area where the camera wont try to re-orientate, the blue or red area is where the camera will try to reorientation from

Settings of the Virtual Camera Component - Generally, a further back follow offset camera is better for vehicles - You can adjust the soft and deadzone offsets to orientate the car to the bottom of the screen with the aim settings

Changing the priority - Default priority is 10, we’re going to set it to 10000 so none of the sinespace cameras will interfere with it

Drop the Virtual Camera into the Primary Camera slot on the Modular Vehicle Component - There is slots here for secondary cameras such as reverse cameras