Hi. I’m making a racing game with the gravity of a planet. The road is around the planet and i need to use gravity body to body.
I have the gravity, but i cant controll the transform of the car. I want to fix the up axis of the car with the vector of the gravity force but i dont know how to do.
My code at the moment is:
var planet : Transform;
function Update () {
var vector = (planet.transform.position - transform.position );
rigidbody.AddForce(vector*rigidbody.mass/10) ;
You could create a new gameobject, put the ship under it as a child, and put your scripts on the new empty object (instead of the ship). That way you can rotate your ship as needed (looks like ninety degrees “right”). The line I posted should be pointing Y away from the planet (though sometimes my math is horrible and it could be pointing Y towards), but you want Y pointing away - in Unity, Y is the Up axis, and generally you want to keep your objects with their Y axis pointing towards their top (just to save headaches :))