Search Unity

  1. Unity 2020.2 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Rotation

Discussion in 'Editor & General Support' started by nooB, Oct 5, 2009.

  1. nooB

    nooB

    Joined:
    Oct 4, 2009
    Posts:
    20
    I m totally stuck trying to figure out the issue :( . Somebody please help


    This is the case:
    I have an animated object following a path. At every corner of the path the object has to rotate 90 degrees.
    I placed empty objects(box) as way points at the corner position. I find the diff b/w the posns of the two to get the direction vector. And whenevr the animated object is near the waypoint i have to rotate it. But when I do as given below, the object rotates in the right direction but moves back to the previous waypoint.

    Code (csharp):
    1.  
    2. Update(){
    3.     myFunction();
    4.     moveDirection = Vector3(inputSteerX,0,inputSteerZ);
    5.    .......
    6. }
    7.  
    8. myFunction(){
    9. var RelativeWaypointPosition : Vector3 = waypoints[currentWaypoint].position - transform.position;
    10.  
    11. inputSteerX = RelativeWaypointPosition.x / RelativeWaypointPosition.magnitude;
    12. inputSteerZ = RelativeWaypointPosition.z /RelativeWaypointPosition.magnitude;
    13.    
    14. if ( RelativeWaypointPosition.magnitude < 1 ) {
    15.     currentWaypoint ++;
    16.     if(currentWaypoint > 1)
    17.         transform.Rotate(0,90,0);
    18. }
    19. }
    Is this something to do with local rotation vs world rotation
     
  2. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    Can you post a bit more of the code you are using? It isn't clear how you are moving the object, but I suspect there is a problem with the code that chooses the next waypoint based on position.
     
unityunity