Topdown Car Game - Killing orthogonal velocity

Discuss issues specific the Java port of Box2D
ThinSkin
Posts: 2
Joined: Tue Jun 07, 2016 5:59 pm

Topdown Car Game - Killing orthogonal velocity

Hello guys,

This one goes out to all math & physics experts!

I am making a top-down-car game.

Code: Select all

`private void killOrtho(Body targetBody) {        Vector2 localPoint = new Vector2(0, 0);        Vector2 velocity = targetBody.getLinearVelocityFromLocalPoint(localPoint);        double angle = -targetBody.getTransform().getRotation() * 180 / Math.PI + 90;        float vX = -(float) Math.cos(angle / 180 * Math.PI);        float vY = (float) Math.sin(angle / 180 * Math.PI);        Vector2 sidewaysAxis = new Vector2(vX, vY);        sidewaysAxis.scl(velocity.x * sidewaysAxis.x + velocity.y * sidewaysAxis.y);        targetBody.setLinearVelocity(sidewaysAxis);    }`

I figured out this kills the orthogonal velocity on all tires. If I don't do that it's like the car was on ice.
But when I do it, it's driving like a train on rails!

Take a look at my jars to get the idea: