- Home /
Not rotating around the correct pivot point?
Hello in my movementscript im trying to rotate the player when D or A is pressed accordingly. I set up a rotationpoint and made sure it rotates around that point. But the player still rotates around an other point and it makes the player slide around on the ground like the moon around earth. If i switch between pivot and center it is in the same place! here is my code i dont know what im doing wrong:
//ROTATE
if (Input.GetKey (KeyCode.D)) {
transform.RotateAround(RotatePoint.transform.position, Vector3.up, 2);
}
if (Input.GetKey (KeyCode.A)) {
transform.RotateAround(RotatePoint.transform.position, -Vector3.up, 2);
}
Answer by fluxhackspro · May 07, 2018 at 10:38 PM
Thank you @Vicarian for pointing out that im getting the charactercontroller speed from A and D as well from Input.GetAxis!
Answer by Vicarian · May 07, 2018 at 06:58 PM
Usually if you're rotating an object, the rotation is done in the object's local space. By using RotateAround in that manner, you're telling your object to rotate around a fixed axis in world space. So, let's say you have an rotation point at the origin <0, 0, 0>, and your object is at <1, 0, 1>. As the object rotates with RotateAround, its position will update with respect to the origin, so essentially its path will draw a unit circle about the origin parallel to the xz plane.
To account for the objects position in world space, simply use transform.Rotate(Vector3.up, 2);
So what rotate method should i use ins$$anonymous$$d? Before i change to this method i used this but it did the same: transform.eulerAngles = transform.eulerAngles + new Vector3 (0, -90, 0) 2 Time.deltaTime;
That calculation probably isn't correct. Simply use transform.Rotate(Vector3.up, 2);
it STILL rotates around like i told you earlier.
Your answer
Follow this Question
Related Questions
Rotating GUI issues, issues with X,Y cords. 1 Answer
Trying to rotate player, how? 0 Answers
Arbitrary rotation around a point works except when up flips? 1 Answer
Rotating Cuboid Around Pivot 2 Answers