Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved How To Rotate Around Over 360°?

Discussion in 'Scripting' started by Threeyes, Jul 20, 2020.

  1. Threeyes

    Threeyes

    Joined:
    Jun 19, 2014
    Posts:
    80
    I have two items A and B, they both hover over point C with the same distance in 3D, and B will keep following A.
    upload_2020-7-20_19-33-55.png

    I had try transform.RotateAround, but the result will become strange due to this method can't handle the situation when A's rotation is crossing the line between 0°/360°.

    Thanks for your kind help;)
     
  2. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,605
    How have you used RotateAround?
    https://docs.unity3d.com/ScriptReference/Transform.RotateAround.html

    As its last value you simply pass how many degrees it should rotate (multiplied by Times.deltaTime for a per frame value). Crossing 360° should not have any meaning in this approach.

    You can however also keep track of your own value entirely, increment that each frame, then reset the rotation of the object on the axis in question and use RotateAround with your internal value (without Time.deltaTime).

    Neither of these should have any problems crossing 360° to my knowledge.
     
    Threeyes likes this.
  3. Threeyes

    Threeyes

    Joined:
    Jun 19, 2014
    Posts:
    80
    Thank you, there may be some mistake on my normal calculation, i had try another way to achieve this (use Vector3.Lerp to follow A, then project the new position on the Sphere).