- Home /
Rotating around to a point
I have a camera set up in my scene to rotate around a planet with player input. This uses the RotateAround method and works well. I want to have my camera rotate around the planet automatically like that but stop when it reaches a point.
The code I'm using to rotate using player input:
transform.RotateAround(center,transform.up,Input.GetAxis("Horizontal")*rotationSpeed*Time.deltaTime);
//center is referring to the center of the planet
I've tried using iTween, but I don't like using very much. Is there a way to rotate around to a point using RotateAround or something similar? Thanks in advance.
How is the point you want to reach defined? If it is an angle, simply compare against whatever value you use for the last parameter of RotateAround, which is an angle value. In your case:
Input.GetAxis("Horizontal")*rotationSpeed*Time.deltaTime
Answer by Vivek-Joshi · Sep 22, 2015 at 10:48 AM
Agreed with @Glurth. If it is a fixed position/angle, you can check it and stop rotating after that.
Vector3 center = Vector3.zero;
float rotationSpeed=10f;
float destinationPoint = -1f;
void Update()
{
if((int)transform.localPosition.x != (int)destinationPoint)
{
transform.RotateAround(center,transform.up,Input.GetAxis("Horizontal")*rotationSpeed*Time.deltaTime);
}
}
Just replace localPosition with localEulerAngles, if you want to check the angles.
This is just for the demo, you will have to replace the values of your own.
@CulturedSpud Hope this helps, Thank you.
Your answer
![](https://koobas.hobune.stream/wayback/20220612034036im_/https://answers.unity.com/themes/thub/images/avi.jpg)