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

Combinate Lerp and Rotation in a game

Discussion in '2D' started by Joralin, Oct 12, 2014.

  1. Joralin

    Joralin

    Joined:
    Aug 27, 2014
    Posts:
    30
    Hi,

    i create a game, where you controling a bird and let him fly do different directions. The bird has a fixed start point and the end point is always the point, the player klicking at.

    The gamemechanics are using ".lerp" and working well.


    But how can i create a function, that takes care, that the picture of the gamecharacter is always beeing rotatet in the correct angle for the current "flight" ? ( You never know in which direction and angle the player is controling the bird)
     
  2. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
  3. Joralin

    Joralin

    Joined:
    Aug 27, 2014
    Posts:
    30
    Thank you very much. Strange that my Gameobject dissapears when i use "Look Rotation".. But i hope i will get it to work.
     
  4. Pyrian

    Pyrian

    Joined:
    Mar 27, 2014
    Posts:
    301
    The various "look" functions do not work for 2D Sprites; they point the Z-axis, which inevitably makes the Sprite edge-on to the camera, therefore "disappearing" as it has no width.

    Instead you'll have to use Mathf.Atan2.
     
    Joralin likes this.
  5. Joralin

    Joralin

    Joined:
    Aug 27, 2014
    Posts:
    30
    Ah ok, thank you :)
     
  6. Joralin

    Joralin

    Joined:
    Aug 27, 2014
    Posts:
    30
    Hmm ok, i cant work with rotating by an angle. I have to many possibilities in my game and the angle just works for a certain "fly position".

    Is there no way to make use of "rotate towards and certain point?
     
    Last edited: Oct 30, 2014