Exemplo n.º 1
0
 //subscribed to OnStateChanged event
 private void GetPath(BaseState state)
 {
     if (state is FleeState && character is TownspersonClass)
     {
         path = PathFinding.AStarJump(character.floorPosition, ((TownspersonClass)character).building.entrance.transform.position, character.nodeMap, character.nodeID);
     }
 }
Exemplo n.º 2
0
    public override Type Tick()
    {
        rb.velocity = Vector2.zero;

        //if valid LOS, attack
        if (HasLineOfSight())
        {
            path.Clear();
            return(typeof(RangerAttackState));
        }

        //else move towards player while checking
        if (path.Count == 0)
        {
            path = PathFinding.AStarJump(ranger.floorPosition, player.floorPosition, ranger.nodeMap, character.nodeID);
        }
        else
        {
            rb.velocity = PathFinding.GetVelocity(ranger.floorPosition, path[0], ranger.speed);
            if ((ranger.floorPosition - path[0]).sqrMagnitude <= PathFinding.TOLERANCE)
            {
                path.RemoveAt(0);
            }

            //if we reach where the end of path without LOS, go to idle
            if (path.Count == 0)
            {
                ranger.SetIsAlarmed(false);
                return(typeof(RangerIdleState));
            }
        }
        return(null);
    }