Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved How can I calculate an objects rotation around a given point?

Discussion in 'Scripting' started by lambch0p, Apr 25, 2022.

  1. lambch0p

    lambch0p

    Joined:
    Oct 22, 2014
    Posts:
    62
    Hi,

    I have a game that happens inside a tube. The player is moved around the inner surface of the tube by using RotateAround on the z-axis.

    The evil pigeon is spawned at far end of the tunnel and hurtles towards the player in a blur of flapping death. I need the pigeon to try to match the players rotation (homing pigeon) but cannot figure out how to calculate the players rotation relative to the z-axis of a given point (0,0,0 in this case) in order to lerp the pigeon towards it.

    In short. If there are two objects on a circle and they rotate around the center point, how can I get one object to try to match the others rotation around that center point.

    upload_2022-4-25_5-57-38.png
     
  2. lambch0p

    lambch0p

    Joined:
    Oct 22, 2014
    Posts:
    62
    Duh-nuh


    private float GetAngle()
    {
    var angle = Vector3.SignedAngle(pigeon.transform.position, player.transform.position, Vector3.forward);
    return angle;
    }