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

Quaternion.Slerp starts fast and then going to the end with death slow :(

Discussion in 'Scripting' started by TOLGA-YAVUZ, Jun 1, 2014.

  1. TOLGA-YAVUZ

    TOLGA-YAVUZ

    Joined:
    Feb 9, 2014
    Posts:
    4
    Hi guys,

    Here is my code,

    Code (csharp):
    1.  
    2. void yurumek(Vector3 target, float speed)
    3.     {
    4.         Vector3 this = transform.position;
    5.         Vector3 bak = target-this;
    6.         bak.y = 0;
    7.         Quaternion rotation = Quaternion.LookRotation(bak);
    8.         transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime);
    9.  
    10.         if(transform.rotation != rotation) { speed = 1; } else { speed = 5; }
    11.         transform.Translate(Vector3.forward * Time.deltaTime * speed );
    12.     }
    13.  
    I'm working on pedestrian AI, this function about to walk to target. My NPC starts to walk slowly to target at the same time facing to it, when npc's face to target it is starts to go faster but that Quaternion.Slerp starts to face quickly but when close to end it is facing like dead speed and makes me problem at that part
    Code (csharp):
    1. if(transform.rotation != rotation)
    Waiting your helps.
     
  2. TOLGA-YAVUZ

    TOLGA-YAVUZ

    Joined:
    Feb 9, 2014
    Posts:
    4
    Fixed with that
    Code (csharp):
    1. if(Quaternion.Angle(transform.rotation, rotation) > 5.0F)