Fix 2 Axis from different objects.

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

if(Input.GetKey(“w”))
rigidbody.AddRelativeForce (Vector3(1,0,0) * -100);

}

transform.rotation = Quaternion.LookRotation( transform.forward, vectorAwayFromGround );

Thanks Vicenti. But im very noob and it isn’t still working.

The spaceship that i called the car, now try to get always the same face grunded, but isn’t the correct face.

:frowning:

the local axis of the spaceship that looks at the center of the planet is the Y axis, the green.

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

Ok, the spaceship is in ok alignmeng now. I had exported again rotating 90º.

Now my problem is a balance that makes unstable the control. The spaceship is almost always spining and balancing his x axis

http://www.megaupload.com/?d=FAK8B4O6
Here is the game.