# Box2d topdown racing game - killing “residual” forces

I'm making top-down race game in GM:S with Box2D, the car is controled in unusual way: player sets direction and engine's speed, and the car uses them: turns to the desired direction and reaches speed. But the question is about the "residual" speed after the turn. Here is what I mean:

I make rotation by applying torque and move with applying force. I don't have tyres, it's just one plain object.
So how can I get rid of this momentum? I'm working in GM:S, but I'd like to hear any solution, I can adapt it easily.

Movement code:

var ad = angle_difference(phy_rotation, desiredDir);
physics_apply_torque((angleTorque) * -sign(ad)); // rotate the car

dx = lengthdir_x(spd, -phy_rotation);
dy = lengthdir_y(spd, -phy_rotation);

physics_apply_force(phy_position_x, phy_position_y, dx, dy);  // move the car

• It would be helpful to see the code you are using. I suspect you want to use a force perpendicular to the car, rather than a torque force. The torque force won't interact with the existing movement. – Chris Jul 21 '17 at 20:12
• @Chris I added the movement code, but I don't think that it's because of the torque. Even if it is, how can I get rid of the momentum? – German Gorodnev Jul 22 '17 at 9:50

## Combination of Forces

Instead of using a Torque force to steer the car, apply force perpendicular to the direction it is traveling. This is very roughly how the physics actually works.

When you apply the force perpendicular to the forward direction, the forward force and the perpendicular force will combine over each physics update to change the direction of the car. In this way, the forward force is "negated" by being added to the perpendicular force, creating a new direction for the car.

Torque forces and linear forces do not combine in this way. So using torque to turn is actually not affecting the forward force at all.

You may also need to manually apply a rotation to the car to keep it pointed the same direction as it is currently being moved.

## GML Notes

I haven't worked much with physics in Game Maker, however, I'd look at the local physics functions.

With this it'd probably be easiest to setup three "forces" and apply them as needed for acceleration, left, and right turn.

Forward (assuming from your picture that 0,1 is forward):
physics_apply_local_force(0, 0, 1, 0)

Left Turn:
physics_apply_local_force(0, 0, 0, 1)

Right Turn:
physics_apply_local_force(0, 0, 0, -1)

You should swap out the "1" or "-1" for magnitude of the force.

Game Maker example for handling the rotation: