Пример #1
0
 private void moveKinematic()
 {
     if (Input.GetMouseButtonDown(0))
     {
         destination   = DirectionUtility.getMouseDirection();
         destination.y = transform.position.y;
         go            = true;
         calculating   = true;
         inizializeTree(destination);
         draw.clean();
     }
     else
     {
         if (go && path.Count > 0)
         {
             destination = (Vector3)path[path_index];
             float d = Vector3.Distance(transform.position, destination);
             if (d > 0.5)
             {
                 Vector3 direction = (destination - transform.position).normalized;
                 DirectionUtility.makeKinematicMove(rigidbody, direction, speed);
             }
             else
             {
                 rigidbody.velocity = Vector3.zero;
                 transform.position = destination;
                 path_index++;
                 if (path_index == path.Count)
                 {
                     go = false; path_index = 0;
                 }
             }
         }
     }
 }
Пример #2
0
    private void moveKinematic()
    {
        if (Input.GetMouseButtonDown(0))
        {
            destination   = DirectionUtility.getMouseDirection();
            destination.y = transform.position.y;
            go            = true;
            draw.clean();
            path_index = 2;

            calculating = true;
            inizializeTree(transform.position, destination);
        }
        else
        {
            if (go && path.Count > 0)
            {
                Vector3 dest = (Vector3)path[path_index];
                //Debug.Log(path.Count+" "+path_index+" "+path[path_index]);
                //makeMove(dest);

                float d = Vector3.Distance(transform.position, dest);
                if (d > 1f)
                {
                    Vector3 direction = (dest - transform.position).normalized;
                    //correctAngle(direction);
                    //DirectionUtility.makeKinematicMove (rigidbody, direction, speed);
                    DirectionUtility.makeCarMove(rigidbody, transform, direction, speed);
                }
                else
                {
                    rigidbody.velocity = Vector3.zero;
                    //transform.position = dest;
                    //Debug.Log(path.Count+" "+path_index);
                    path_index++;
                    if (path_index == path.Count)
                    {
                        go = false;
                    }
                }
            }
        }
    }