Making a raycast car

From Newton Wiki
Jump to: navigation, search

For some reason if you wouild like to implement a raycast car instead of the built in car module, following may be helpful.

Implementing tires/suspension

First we assume that the interaction of the tires with other rigid bodies is neglected.

Next, as the name implies, we assume that each tire can be modeled by a simple raycast. To do this we need the raycast origin of the tire and the length of the ray. These are both input parameters:

M_car = abs transformation of the carbody;
V_susp = rel transformation of the suspension base on carbody;// doesnt need orientation
L_susp = suspension max. length;
L_tirerad = tire radius;

ray_origin = M_car x V_susp;
ray_length = L_susp + L_tirerad;

       +---x----+    ^
      /  +---+  \    | suspension_length
    -/  /     \  \-  |  
        |  o  |      X  
        \     /      | tire_radius
         +---+       v

x: absolute suspension base on car body

The length of the raycast(L_ray) gives the compression of the tire by:

L_comp = L_ray-tire_radius;

Note that if the ray does not hit anything, the tire will be airborne: L_comp = 0.

Store the hit point in the world: V_tirept.

Suspension forces

Now that we know the compression of each suspension, we can calculate the suspension forces and apply the appropriate torque/force in NewtonBodySetForceAndTorqueCallback.

k_susp: Sprint constant
k_damp: Damping constant

For now let's assume the rebound and bump damping equal.(if you dont know what this means it is ok)

also let's define another variable, L_comp_prev: compression level used in the previous iteration

After each iteration we store the current compression in the L_comp_prev. Now we have two type of force on the suspension:

F_spring: Spring force
F_damp: Damping force

Spring force will push the body up and the damping force will make sure that the body will not "wobble" infinitely, and the oscillation will die out in finite time. The parameters k_susp and k_damp are crucial in determining a realistic feeling suspension

F_spring = L_comp x k_susp;
F_damp = (L_comp - L_comp_prev)*k_damp;

For all tires, this force is applied at the point of raycast hit (V_tirept) during the force and torque callback.

<<Sample code to come>>

Longitudal forces

<< to come >>

Lateral forces

<< to come >>