# Box2D—how make character tilt

I have got a floating character, which should be a robot like thing, floating over the ground, whereby I am using the »hovercar« effect described here. Zhe Image below outlines the basic setup of the physics

The Green rectangle is the chassis, its not allowed to rotate and held up by the »hover-power«. Attached to this is the robots head with an revolute joint, and attached to the head is the robots body, with another revolute joint. There are some more distance Joints for damping this, but not of interest for now.

In the next image one can see how the body of the robot should be tilted when it is in motion to the right or left.

Right now, the movement of the character is implemented so that forces and impulses are applied to the chassis body. Especially if there is an Impulse to the left or right, the desired tilt of the robots body comes to happen, but it fades away when the velocity becomes more constant, or acceleration comes closer to zero.

What can I do to keep the robots body tilted, when it is in motion?

• Apply a light force to the bottom of the object in the opposite direction? Commented Mar 31, 2014 at 21:04
• Yes, that's probably a good Idea, but I am looking for a more »code less« way, just using joints, damping or something like that—something box2d brings »out of the box«. My tests with linear damping just slowed down the whole character, so I am searching for an alternative way… Commented Apr 1, 2014 at 11:09
• Applying forces are pretty much what Box2D is built around. Commented Apr 1, 2014 at 13:27
• Yes, that is absolutely true, but applying the force needs to be triggered by code. Would be fine if there would be a solution which can be modeled within RUBE. Commented Apr 1, 2014 at 14:13
• You can set the LinearDamping property of the body, then it will automatically apply forces that resist motion. Commented Jan 2, 2015 at 2:39

The move of the body is due to the air resistance.
You should apply a -k*v force to the lower part of the body.
Or even more accurate : project the speed vector on the frontmost line of the body : you now have Speed = (sx',sy'). Now apply two different coefficient, k1 and k2, for sx' and sy'. k1 would be the coefficient induced by some air coming face to the body, and k2 is the coefficient when the air comes from below the body (like 8 times smaller).
This way you'll have a realistic behavior : when going up the robot will be aligned, and the effect when going right or left will be the one you seek.

F = -k1 * sx ' * U - k2 * sy' *  V
Or :
F = - k1 * ( S • U ) * U - k2 * ( S • V) * V


Why dont you apply force during the render thread. You can set a boolean value start and stop the tilt, since its under the render thread it will probably stay tilted since that same force is being applied constantly

• It is a very bad idea to do physics in rendering thread. It breaks the whole encapsulation thing... Commented Apr 2, 2015 at 14:30