Ejemplo n.º 1
0
    private void MoveMethod()
    {
        if (!do_it)
        {
            do_it = true; return;
        }
        if (Path.Count > 0)
        {
            Vector2 transform_position = transform.position;
            Vector2 direction          = ((Vector2)Path[0].position - transform_position).normalized;
            Vector2 velocityVector;

            Vector2 rb_velocity = my_rigidbody.velocity;
            if ((rb_velocity - direction * current_speed).magnitude > current_speed / 5)
            {
                velocityVector        = Vector2.Lerp(rb_velocity, direction * current_speed, velocity_lerp);
                my_rigidbody.velocity = velocityVector;
                rb_velocity           = velocityVector;
            }

            float velocity_magnitude = rb_velocity.magnitude;


            if (Vector2.Distance(transform_position, Path[0].position) < howclose)
            {
                previousPath = Path[0];
                Path.RemoveAt(0);
            }
            if (rethink)
            {
                rethink = false;
            }
        }
    }
Ejemplo n.º 2
0
 public void FindPath(int path, Vector2 startPosition, Vector2 endPosition, WaypointNodelet previousPoint)
 {
     if (PathType == PathfinderType.GridBased)
     {        //Debug.Log("gridbased findpath");
         //  Pathfinder2D.Instance.InsertInQueue(startPosition, endPosition, SetList);
     }
     else if (PathType == PathfinderType.WaypointBased)
     {
         WaypointMultiPathfinder.Instance.InsertInQueue(path, startPosition, endPosition, SetList);
     }
 }