- Home /
Rotation around sphere
hi :) i need to rotate a spceships around planet.
function OnTriggerEnter (planetGrav : Collider)
{
isOnPlanet = true;
if(Physics.Raycast(transform.position, rotationPoint - transform.position, rayHit, Mathf.Infinity, ~9)) //9 is planet's layer
{
if(rayHit.collider.name == "planet")
{
transform.rotation = Quaternion.FromToRotation(Vector3.up, rayHit.normal);
}
}
}
when spaceship came to planet, it rotates to match planet's surface. only once. then rotating spaceship around planet:
function UnitAngle()
{
if(isOnPlanet)
{
transform.RotateAround(rotationPoint, Vector3.down, Time.deltaTime * angularSpeed);
}
}
the problem is that spaceships almost always "looking" in wrong direction. for example: spaceship's rotation is counterclockwise, but it's "nouse" looking not to its moving vector, but up, or anywhere else.
Answer by Shuher · May 18, 2015 at 01:43 PM
that is solves it :)
transform.rotation = Quaternion.LookRotation(Vector3.Cross(-rayHit.collider.transform.up, transform.position - rayHit.collider.transform.position), transform.position - rayHit.collider.transform.position);
Your answer
Follow this Question
Related Questions
Rotate the object using device acceleration 1 Answer
transform.RotateAround in a specific amount of time? 1 Answer
Smoothfollow script C# How to rotate the camera? 0 Answers
How can I make a object/sprite rotate around another object/sprite using rigidbody 0 Answers
Make object rotate about a circle with fixed velocity after collision 0 Answers