# Real Physics Enabled Racing Game

**URL:** <https://forum.babylonjs.com/t/real-physics-enabled-racing-game/4034>\
**Category:** Questions\
**Created:** [June 21, 2019, 8:41am UTC](https://forum.babylonjs.com/t/real-physics-enabled-racing-game/4034 "2019-06-21T08:41:59Z")\
**Posts on this page:** 1\
**Showing post:** 24

<div class="post-metadata">

**Author:** ![Raggar](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raggar/32/20672_2.png) [@Raggar](https://forum.babylonjs.com/u/Raggar)\
**Post date:** [June 28, 2019, 6:40pm UTC](https://forum.babylonjs.com/t/real-physics-enabled-racing-game/4034/24 "2019-06-28T18:40:35Z")

</div>

I’ve taken the bit and parts and ported them over one by one. If I remember correctly, very few, if any, changes are needed to make it work.

In the castRay function of your raycaster, you simply put:

```auto
 rayCallback.m_collisionFilterMask = collisionFilterMask;
 rayCallback.m_collisionFilterGroup = collisionFilterGroup;

```

Before you do the rayTest.  
So between setting the result callback and calling the rayTest function. Then it’s automatically handled.

Then you just need a way of setting your mask and group. The best way of doing this is to create a function that takes two ints, one for the mask and one for the group, and do collisionFilterMask = BIT(int)  
Then export this function in the idl.

A cool feature of the SuperTuxKart project as well is auto-stabilization of the vehicle when airborne.  
You can give it a Vector3 telling it which direction is up (0,1,0), and an int or float as an impulse to automatically stabilize the vehicle, so it hits the ground correctly.

```auto
        btVector3 kart_up = getChassisWorldTransform().getBasis().getColumn(1);
        //btVector3 terrain_up = btVector3(0, 1, 0);
        // Length of axis depends on the angle - i.e. the further awat
        // the kart is from being upright, the larger the applied impulse
        // will be, resulting in fast changes when the kart is on its
        // side, but not overcompensating (and therefore shaking) when
        // the kart is not much away from being upright.
        btVector3 axis = kart_up.cross(terrain_up);

        // To avoid the kart going backwards/forwards (or rolling sideways),
        // set the pitch/roll to 0 before applying the 'straightening' impulse.
        // TODO: make this works if gravity is changed.
        btVector3 av = m_chassisBody->getAngularVelocity();
        av.setX(0);
        av.setZ(0);
        m_chassisBody->setAngularVelocity(av);
        // Give a nicely balanced feeling for rebalancing the kart
        m_chassisBody->applyTorqueImpulse(axis * stabImpulse);

```

---

_[View the full topic](https://forum.babylonjs.com/t/real-physics-enabled-racing-game/4034)._
