Topdown Car Game - Killing orthogonal velocity

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

Topdown Car Game - Killing orthogonal velocity

Postby ThinSkin » Tue Jun 28, 2016 6:43 pm

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);

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:

How can I only kill parts of the orthogonal velocity and still allow drifting?

Hope you can help me with that, thanks,

Return to “Java”

Who is online

Users browsing this forum: No registered users and 2 guests