- Home /
Planetoid Gravity
Hello, I've started a project in wich there are planetoids but I have a problem making my custom gravity.
My first tought was to first make the player look to the center of the planet and then apply the rotation to look the new up, but there is a problem I didn't count, when unity uses lookAt at the planet the up vector will always be upside the planet so the player will be always looking at the north of the planetoid and that's a problem jajaja.
My second tought was to make the down vector of the player to look at the center of the planet but I don't know how to make that.
can Anyone help me?
Answer by robertbu · Jul 15, 2014 at 12:43 AM
Planetoid gravity has been covered numerous times on UA. The solution will vary somewhat based on your game mechanic. The typical solution using a smooth sphere is:
var worldUp = transform.position - planetoid.position;
transform.rotation = Quaternion.FromToRotation(transform.up, worldUp) * transform.rotation;
And you want to do this alignment before you process 'y' rotation code for the object.
thanks!!! with only that two lines of code it works!!
Your answer
Follow this Question
Related Questions
Transform a Vector by a Quaternion 1 Answer
LookRotation Vector3 is Zero, Yet Slerp Still Rotates? 2 Answers
Instantiate GameObject towards player 0 Answers
Random.insideUnitCircle seems to reproduce similar vectors 1 Answer
Rotation of object placed in the middle point between two points? 0 Answers