Search Unity

Figuring out what is the fastest way to reach a heading.

Discussion in 'Scripting' started by Napivo, Mar 1, 2015.

  1. Napivo

    Napivo

    Joined:
    Feb 9, 2015
    Posts:
    39
    This is for my spaceship. Imagine is want to indicate the direction the player needs to rotate to reach the wanted angle the fastest.

    Given 2 vector3 position, Player and Target and the heading of the player.

    How can I make a 2d sprite indicate that the player needs to turn up down left or right to reach the targeted angle?

    Getting the target direction is easy
    Code (CSharp):
    1. Vector3 wantedheading = SelectedObject.transform.position - Player.transform.position;
    2. Vector3 curentheading = Player.transform.localRotation.eulerAngles;
    But now what? I have tried and tried but I just can't figure it out.

    Any help much appreciated.
     
  2. Timelog

    Timelog

    Joined:
    Nov 22, 2014
    Posts:
    528
    Is there a reason you can't just use transform.LookAt(wantedheading) to turn you ship to the correct angle immediately?
     
  3. Napivo

    Napivo

    Joined:
    Feb 9, 2015
    Posts:
    39
    I want to have an indicator that always points in the direction of the selected object, if it is not on the screen.
     
  4. Timelog

    Timelog

    Joined:
    Nov 22, 2014
    Posts:
    528
    If that indicator is something like an arrow pointing to the location I would give that the transform.lookat script then, otherwise I would create an empty gameobject, have that look at the target and show it's angels on screen in numbers if that is what your idea was.