UnigineScript
The Language
Core Library
Engine Library
Node-Related Classes
GUI-Related Classes
Plugins Library
Samples
C++ API
API Reference
Integration Samples
Usage Examples
C++ Plugins
Content Creation
Materials
Unigine Material Library
Tutorials

Vehicles

As City Traffic is based on Game Framework, each vehicle is an entity with a node reference assigned. The base class for vehicles is named "Car". Each car variation should be saved as a separate .node file.

ObjectMesh Settings

An ObjectMesh should be a root node for the car's node reference. This object should have a BodyRigid with the required shapes. Further, a joint will be assigned to this BodyRigid.

A Car's ObjectMesh

Another important element of the car's geometry is a surface replicating a car's bounding box. This surface is used to detect the car by intersection rays. It's intersection mask should be 0x00000100.

For special signals (turn signals, headlights, stop lights), you need to set a special property "signal_surface" and specify a Signal Type parameter. It can be of the following values: turn_left, turn_right, stop, reverse, headlight, dipped_light.

The logic of special signals is simple: if the signal is turned on, its surface is just being enabled and disabled.

Notice
You can add new types of signals and their logic.

Wheels Settings

The system automatically creates a JointWheel object for each wheel and binds it with a car's BodyRigid. For it, you need to do the following:

  • Place the wheels into correct positions.
  • Make them children nodes of the car's ObjectMesh.
  • Create a BodyRigid without shapes for them.
  • Assign a "car_wheel" property to it.

Car's Wheel

A "car_wheel" property has 3 toggle parameters:

  • Steering - for steering wheels.
  • Driving - for car wheels.
  • Hand-brake - for wheels that are locked while pressing a hand-brake.

Physics and Dynamics Settings

Mass and center of gravity are adjusted in the car's node.

Other physics and dynamic parameters are adjusted in the Fields tab of your car class, inherited from the Car class:

  • Gear Ratio - the ratio of the number of a car's gearbox revolutions to the number of wheels revolutions.
  • Gear Ratio Reverse - the reverse gear ratio.
  • Gear Ratio One - the first transmission gear ratio.
  • Gear Ratio Two - the second transmission gear ratio.
  • Gear Ratio Three - the third transmission gear ratio.
  • Gear Ratio Four - the fourth transmission gear ratio.
  • Gear Ratio Five - the fifth transmission gear ratio.
  • Gear Ratio Six - the sixth transmission gear ratio.
  • Gear Ratio Seven - the seventh transmission gear ratio.
  • Final Drive - the ratio of the number of revolutions of the engine to the gearbox number of revolutions.
  • Number Gears - the number of gears.
  • Drive Efficiency - drive gear efficiency
  • Max Steer Speed - the maximum wheel rotation speed
  • Min Steer Speed - the minimum wheel rotation speed
  • Max Rpm - maximum revolutions per minute
  • Min Rpm - minimum revolutions per minute
  • Max Torque - the maximum torque of the wheel
  • Max Angular Damping - the maximum angular wheel resistance while pressing the brake
  • Min Angular Damping - the constant angular resistance of the wheels
  • Hand Brake Angular Damping - the wheel's angular resistance while pressing the handbrake
  • Max Steer Angle - the maximum angle of wheels rotation
  • Suspension Spring - the suspension stiffness
  • Suspension Damping - the coefficient of suspension linear damping
  • Suspension Limit From - the upper limit of the suspension
  • Suspension Limit To - the lower limit of the suspension
  • Wheel Threshold - the wheel threshold
  • Wheel Tangent Friction - the linear scrubbing of a tyre
  • Wheel Tangent Angle - the coefficient, specifying how fast the linear force can be obtained
  • Wheel Binormal Friction - the side scrubbing of a tyre
  • Wheel Binormal Angle - the coefficient, specifying how fast the side force can be obtained
  • Gear Shifting Schedule - the path to the XML file containing rules for the automatic gearbox. For each transmission there are 2 curves in the "throttle"/"speed" coordinates system for up and down switch.

An example of the gear shift rules setting:

Source code (XML)
<?xml version="1.0" encoding="utf-8"?>
<lines>
    <up>
        <line> <!-- gear 1 up -->
            <point throttle="0" speed="16"/>
            <point throttle="25" speed="16"/>
            <point throttle="90" speed="48"/>
            <point throttle="100" speed="48"/>
        </line>
        <line> <!-- gear 2 up -->
            <point throttle="0" speed="48"/>
            <point throttle="35" speed="48"/>
            <point throttle="90" speed="90"/>
            <point throttle="100" speed="90"/>
        </line>
        <line> <!-- gear 3 up -->
            <point throttle="0" speed="80"/>
            <point throttle="35" speed="80"/>
            <point throttle="90" speed="140"/>
            <point throttle="100" speed="140"/>
        </line>
    </up>
    
    <down>
        <line> <!-- gear 2 down -->
            <point throttle="0" speed="8"/>
            <point throttle="50" speed="8"/>
            <point throttle="90" speed="46"/>
            <point throttle="100" speed="46"/>
        </line>
        <line> <!-- gear 3 down -->
            <point throttle="0" speed="32"/>
            <point throttle="50" speed="32"/>
            <point throttle="90" speed="80"/>
            <point throttle="100" speed="80"/>
        </line>
        <line> <!-- gear 4 down -->
            <point throttle="0" speed="56"/>
            <point throttle="50" speed="56"/>
            <point throttle="90" speed="128"/>
            <point throttle="100" speed="128"/>
        </line>
    </down>
</lines>

The result will be:

Gear Shifting Schedule

Colors Settings

To diversify cars in the world, you can use different colors and materials. For material settings, there is a special built-in system, based on Unigine properties.

To set a meterial, you need to create a property, inherited from the "car_colors" property for each type of cars.

Notice
Note that for each type of cars you need to create a node reference.

A "car_colors" property has two parameters:

  • Material - the name of the material
  • Surface - the number of the surface, onto which a material will be assigned

A "car_colors" property needs to be specified in the Color Base Property field of your car's entity.

Color Settings

All of this property children will represent a list of car's possible colors. To specify all of the surfaces and their materials, you need to create auxiliary children, inherited from a list element:

Property List

On the car's creation, the color will be chosen randomly. The property will check all of the children and assign materials to required surfaces.

Last update: 2017-07-03