Search Unity

Rotation Helpppp!!!!!!!

Discussion in 'Scripting' started by nooB, Nov 5, 2009.

  1. nooB

    nooB

    Joined:
    Oct 4, 2009
    Posts:
    20
    Badly needed help with this. Its a very simple problem but I am not sure where I m going wrong.

    Here s the case:

    I have an animation for a tower of defense game that I am making.
    It follows a path and on its path the character has to orient itself in the path direction. I have created Waypoints for determining the point of change in direction.
    This is what I did
    Code (csharp):
    1.  
    2.  
    3. var nextRelativeWaypointPosition : Vector3 = waypoints[currentWaypoint+1].position - transform.position;
    4. transform.LookAt(nextRelativeWaypointPosition,Vector3.up);
    5.  
    6.  
    But the Character seems to take a circular path around the target.

    I have tried various other functions as well using
    "localrotate" "InversetransformRotation" etc to no avail.

    Suggestions/corrections !!
     
  2. DerWoDaSo

    DerWoDaSo

    Joined:
    May 25, 2009
    Posts:
    126
    Where do you actually move your character? In the script is just the rotation...
     
  3. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    This happens if you are moving the character at a constant speed (ie, the speed is constant and the angular change in direction is constant, so the character is moving in a circle). You need to slow the character down as it approaches the target point.
     
  4. nooB

    nooB

    Joined:
    Oct 4, 2009
    Posts:
    20
    Wonderful !!!
    That worked
     
unityunity