I'd like to develop a 3D vehicle with 2 wheels, in other words, a motorbike.
I tried to implement that by locking z axis rotation, but the problem here is that it seems to lock not on relative node'z axis, but rather the origin's, I'm not sure if that's correct, I'm investigating.
I also tried to simulate counterbalance by rotating along the z axis proportionally to steering and speed, with something like:
var inclination = atan(-steer_angle * _state.linear_velocity.length())
self.rotation_degrees.z = rad2deg(inclination)
but, even if it lean the bike in a semi realistic manner, it seems to rotate not taking into account forces, so tha the bike somehow falls in a weird way. It might be that I should not rotate along an axis but rather apply a torque, I have to try this.
My idea was that I have to move the center of mass by rotating the VehicleBody along Z axis so that the centrifugal force is balanced by the resulting vector of mass center - floor constraint (remove the y element), as I tried to illustrate below.
But the problem is that I can't find a method that gives me the centrifugal force, I'm not even sure if it exists.
Well, I'll surely continue investigating, there might not be a function that does that but maybe I can calculate it manually.
If someone in the meantine finds, or have a solution already, I'll be glad to be enlightened.