This page has been translated automatically.
Getting Started
Migrating to UNIGINE 2.0
C++ API Migration
UnigineScript
The Language
Core Library
Engine Library
Node-Related Classes
GUI-Related Classes
Plugins Library
Samples
Usage Examples
C++ API
API Reference
Integration Samples
Usage Examples
C++ Plugins
Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

Cars

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.

Car Settings

An ObjectMeshStatic should be a root node for the car's node reference.

Warning
Do not change the car's orientation in editor. The mesh should be imported with the proper orientation.

The object should have the BodyRigid body with the required shapes. Further, a joint will be assigned to this BodyRigid.

Car created with the ObjectMeshStatic node

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.

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

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

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 ObjectMeshStatic.
  • Create a BodyRigid without shapes for them.
  • Assign a "car_wheel" property to it.
Warning
Do not change the wheel's orientation in editor. The mesh should be imported with the proper orientation.

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 - ratio of the number of a car's gearbox revolutions to the number of wheels revolutions.
  • Gear Ratio Reverse - reverse gear ratio.
  • Gear Ratio One - first transmission gear ratio.
  • Gear Ratio Two - second transmission gear ratio.
  • Gear Ratio Three - third transmission gear ratio.
  • Gear Ratio Four - fourth transmission gear ratio.
  • Gear Ratio Five - fifth transmission gear ratio.
  • Gear Ratio Six - sixth transmission gear ratio.
  • Gear Ratio Seven - seventh transmission gear ratio.
    Notice
    All of the gear ratio variables are taken from real vehicles. You can find this parameters in the specification of a required car. For example, look at the transmition gear ratios for a Ford Focus.
  • Final Drive - ratio of the number of revolutions of the engine to the gearbox number of revolutions.
  • Number Gears - number of gears in the gearbox.
  • Drive Efficiency - drive gear efficiency (for example, if this parameter is set to 0.7 (70%), the loss of efficiency will be 30%).
  • Max Steer Speed - maximum wheel rotation speed, in degree/second.
  • Min Steer Speed - minimum wheel rotation speed, in degree/second.
  • Max Rpm - maximum rotations per minute.
  • Min Rpm - minimum rotations per minute.
  • Max Torque - maximum torque of the wheel. It is calculated as simulated_car_mass (kg) * real_car_torque (Nm) / real car mass (kg)
  • Max Angular Damping - maximum angular wheel resistance while pressing the brake
  • Min Angular Damping - constant angular resistance of the wheels
  • Hand Brake Angular Damping - the wheel's angular resistance while pressing the handbrake
  • Max Steer Angle - maximum angle of wheels rotation
  • Suspension Spring - suspension stiffness
  • Suspension Damping - coefficient of suspension linear damping
  • Suspension Limit From - upper limit of the suspension
  • Suspension Limit To - lower limit of the suspension
  • Wheel Threshold - wheel threshold
  • Wheel Tangent Friction - linear scrubbing of a tyre
  • Wheel Tangent Angle - coefficient, specifying how fast the linear force can be obtained
  • Wheel Binormal Friction - side scrubbing of a tyre
  • Wheel Binormal Angle - the coefficient, specifying how fast the side force can be obtained
  • Gear Shifting Schedule - 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
Build: ()