- Home /
Rotate GameObject To Look Down
Hello
I have a simple script that is supposed to move a GameObject to a certain point and look down on that point from above.
My script is partially working; the GameObject is moving to the correct point but its not looking down from above. So the rotation is wrong. The GameObject flips upside down.
Can you help me get my GameObject to look straight down?
public class MoveTo : MonoBehaviour {
private Vector3 targetPosition = new Vector3(5, 10, 5);
private Quaternion targetRotation = new Quaternion(90, 0, 0, 0);
private float speed = 6f;
void LateUpdate () {
transform.position = Vector3.MoveTowards(transform.position, targetPosition, Time.deltaTime * speed);
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * speed);
}
}
Answer by sethuraj · Jul 29, 2014 at 07:02 AM
the problem here is that you are trying to use the Euler value as Quaternion.I think you gave the value 90 int Quaternion(90,0,0,0) as 90 degree which will not work.If you want it to rotate 90 degree you have to give it in Euler value.Know the difference between Euler and Quaternion here
For now you can change the code to this
public class MoveTo : MonoBehaviour
{
Vector3 targetPosition = new Vector3(5, 10, 5);
Quaternion targetRotation = Quaternion.Euler (90, 0, 0);
float speed = 6f;
float SLerpSpeed=0.5f;
void LateUpdate ()
{
transform.position = Vector3.MoveTowards (transform.position, targetPosition, Time.deltaTime * speed);
transform.rotation = Quaternion.Slerp (transform.rotation, targetRotation, Time.deltaTime * SLerpSpeed);
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613155251im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Ball Rolling Animation Not Working Properly 0 Answers
Rotating an object towards target on a single axis 2 Answers
Flight Movement with Banking 2 Answers
Help with rotating a sprite with mouse. 2 Answers