This page has been translated automatically.
Unigine Basics
1. Introduction
2. Managing Virtual Worlds
3. Preparing 3D Models
4. Materials
5. Cameras and Lighting
6. Implementing Application Logic
7. Making Cutscenes and Recording Videos
8. Preparing Your Project for Release
9. Physics
10. Optimization Basics
11. PROJECT2: First-Person Shooter
13. PROJECT4: VR Application With Simple Interaction

Assembling the Vehicle

To create the main character — a car, we need its 3D model. You can use your own model: a simplified physical model of the car requires the body and 4 wheels to be implemented as separate objects.

To simplify customization, we recommend using a correctly prepared and imported model, all objects of which are unscaled and have their forward axes oriented towards the Y+ axis.

Let's use the pickup model from the race/props/pickup folder. In the context menu of the pickup.node asset, select Place as Node Content and click in the Editor viewport to add the model with the preset materials.

Customizing the car physical model#

The hierarchy of the car nodes in the scene is as follows:

The car body (pickup_frame), wheels (the wheels group), and a decorative car freshener (car_freshner) will be physically active, all other nodes are the car body children that follow its movements.

Notice
Open the Helpers → Physics menu of the Editor viewport to enable rendering of collision forms and joints in the scene.
  1. In the pickup_frame node parameters, the Physics tab, select the Rigid physical body. Keep the default values in all its settings.
  2. Let's also add a collision shape in the Shapes section and use the simplest and most stable shape: Box shape. Select the Box option from the list and click Add. Click Edit Size to customize the collision shape dimensions and roughly replicate the body shape: the simpler the physical representation, the better it is for calculations.

  3. Let's set the following collision shape parameters:

    • Friction coefficient: 1.0
    • Restitution coefficient: 0.0
    • Car body Mass: 60 kg
    Notice
    The real car body weight is about 2000 kilograms, but for a physical game engine the real mass is not always the best option. The model must simulate the real object's behavior while remaining optimal for real-time computations. Therefore, configuring the physical model is all about selecting coefficients to ensure that the model behaves as naturally as possible.

  4. Disable the Shape Based option to override some parameters manually:

    • CMass (center of mass relative to the model pivot point) — move it towards the hood, since most of the mass is on the mechanisms.
    • ADamping (rotation movements damping coefficient) — increase it a bit to make the car body more stable.

  5. Assign the Rigid physical body to all four wheels.

Configuring Joints#

To link the wheels with the body, we need to configure joints connecting them.

  1. Select the car body pickup_frame node and add four Wheel joints in the Joints section selecting the wheels one by one.

  2. Select joints one by one and click the Fix 0 button for each of them, to move the joint connection point to the center of each wheel. Now each wheel is connected to the car body and will continuously tend to the specified center.
  3. Select all joints using the Shift button and set the following parameter values:

    • Iterations (number of calculation iterations per joint): 2
    • Linear/Angular Restitution coefficients: 0.2
    • Linear Damping coefficient: 300
    • Linear From and Linear To (shock absorber operating range): 0.1 meter. You can increase these values to make suspension more active, but the whole system may become unstable on uneven surfaces and at high speeds.
    • Linear Spring (shock absorber force): 500
    • Tangent/Binormal Friction (longitudinal and transverse friction coefficients for tires): 4.0 and 1.0. You can try different values and adjust the grip between the tires and the ground.
    • Wheel Mass: 10 kg
    • Wheel Radius: 0.37 m for the provided model. If you use your own 3D model, set the wheel radius value corresponding to your model wheels.

  4. Each Wheel joint represents a virtual wheel and uses so-called Physics Intersections to preform a simplified detection of collisions with the ground surface.

    Select the ground_plane node and enable the Physics Intersection option. This will make the geometry "visible" to the joints that simulate the wheels. And enabling the Collision option makes the geometry available for traditional collisions with collision shapes, such as the car body.

  5. Save the changes (Ctrl+S) and enable physics simulation in the Editor to verify that the physics model is correct. Now the car should gain weight and stand on wheels, and the shifted center of mass and rather heavy wheels will make it more resistant to rollover.

    Now disable the physics simulation to continue fine-tuning.

Fine-Tuning Air Freshener (optional)#

Adding dynamic details like this can add to the car driving experience.

  1. Select the car_freshner node and assign the Rigid body to it in the Physics tab.
  2. Add the Box collision shape.
  3. Select the pickup_frame node and add the Ball joint in the Joints section. Press the Fix 0 button in its settings to shift the joint center to the current position of the freshener node.
  4. Configure its parameters as follows:

    • Damping coefficient: 1.0
    • Physical bodies connected with a joint won't collide if the Collision option is disabled, let's keep it as it is.
    • Angle (maximum possible swing angle from the initial position): 155

Now the air freshener will move actively depending on the loads experienced by the vehicle.

Last update: 2024-08-16
Build: ()