Exemplo n.º 1
0
 public override void SetTarget(Killable value)
 {
     target = value;
     if (value != null)
     {
         //Debug.Log("SET TARGET TO: " + value.name);
         state = NpcSoldierState.Chase;
     }
 }
Exemplo n.º 2
0
    private void Follow()
    {
        if (path == null)
        {
            AssignFollowPosition();
        }
        var followForce = GetFollowForce();

        var pitchYaw = GetSteerToPoint(path[curPathIndex]);

        vehicle.SetPitchYaw(0f, pitchYaw.y);
        var forward = Vector3.Dot(followForce, vehicle.transform.forward);
        var strafe  = Vector3.Dot(followForce, vehicle.transform.right);

        vehicle.SetAimAt(path[curPathIndex] + vehicle.PathAimHeight * Vector3.up + vehicle.transform.forward);
        vehicle.SetRun(false);
        vehicle.SetMove(forward, strafe);

        if (!reachedPathEnd)
        {
            var toPathDestination = path[curPathIndex] - vehicle.transform.position;
            if (toPathDestination.sqrMagnitude <= 1f)
            {
                curPathIndex++;
                if (curPathIndex == path.Length)
                {
                    reachedPathEnd = true;
                }
            }
        }

        if (reachedPathEnd)
        {
            AssignWanderPosition();
            reachedPathEnd = false;
            curPathIndex   = 0;
            //vehicle.SetMove(0f, 0f);
        }

        // Reconsider target
        if (targetReconsiderCooldown > 0f)
        {
            targetReconsiderCooldown -= Time.deltaTime;
            if (targetReconsiderCooldown < 0f)
            {
                target = Targeting.FindNearest(Targeting.GetOpposingTeam(Team), vehicle.transform.position, 100f);
                targetReconsiderCooldown = TargetReconsiderRate;
            }
        }

        if (HasTarget())
        {
            state = NpcSoldierState.Chase;
        }
    }
Exemplo n.º 3
0
 private void SetNoTargetState()
 {
     path = null;
     if (DefaultFollowPlayer)
     {
         state = NpcSoldierState.Follow;
     }
     else
     {
         state = NpcSoldierState.Wander;
         AssignWanderPosition();
     }
 }
Exemplo n.º 4
0
    private void Update()
    {
        Heading = transform.forward;
        switch (state)
        {
        case NpcSoldierState.Idle:
            break;

        case NpcSoldierState.Follow:
            Follow();
            break;

        case NpcSoldierState.Wander:
            Wander();
            break;

        case NpcSoldierState.Chase:
            Chase();
            break;
        }
        lastState = state;
    }
Exemplo n.º 5
0
    private void Update()
    {
        Heading = transform.forward;
        switch (state)
        {
        case NpcSoldierState.Idle:
            break;

        case NpcSoldierState.Follow:
            Follow();
            break;

        case NpcSoldierState.Wander:
            Wander();
            break;

        case NpcSoldierState.Chase:
            Chase();
            break;
        }
        lastState = state;

        if (speechCooldown >= 0f)
        {
            speechCooldown -= Time.deltaTime;
            if (speechCooldown < 0f)
            {
                var sounds = vehicle.GetComponent <SoldierSounds>();
                if (sounds != null)
                {
                    sounds.RandomSpeak();
                    speechCooldown = Random.Range(minSpeechTime, maxSpeechTime);
                }
            }
        }
    }
Exemplo n.º 6
0
 public override void SetTarget(Killable value)
 {
     target = value;
     if (value != null)
     {
         //Debug.Log("SET TARGET TO: " + value.name);
         state = NpcSoldierState.Chase;
     }
 }
Exemplo n.º 7
0
    private void Wander()
    {
        if (path == null)
            AssignWanderPosition();
        var wanderForce = GetWanderForce();

        var pitchYaw = GetSteerToPoint(path[curPathIndex]);
        vehicle.SetPitchYaw(0f, pitchYaw.y);
        var forward = Vector3.Dot(wanderForce, vehicle.transform.forward);
        var strafe = Vector3.Dot(wanderForce, vehicle.transform.right);
        vehicle.SetAimAt(path[curPathIndex] + vehicle.PathAimHeight*Vector3.up + vehicle.transform.forward);
        vehicle.SetRun(false);
        vehicle.SetMove(forward, strafe);

        if (!reachedPathEnd)
        {
            var toPathDestination = path[curPathIndex] - vehicle.transform.position;
            if (toPathDestination.sqrMagnitude <= 1f)
            {
                curPathIndex++;
                if (curPathIndex == path.Length)
                {
                    reachedPathEnd = true;
                }
            }
        }

        if (reachedPathEnd)
        {
            AssignWanderPosition();
            reachedPathEnd = false;
            curPathIndex = 0;
            //vehicle.SetMove(0f, 0f);
        }

        // Reconsider target
        if (targetReconsiderCooldown > 0f)
        {
            targetReconsiderCooldown -= Time.deltaTime;
            if (targetReconsiderCooldown < 0f)
            {
                target = Targeting.FindNearest(Targeting.GetOpposingTeam(Team), vehicle.transform.position, 100f);
                targetReconsiderCooldown = TargetReconsiderRate;
            }
        }

        if (HasTarget())
        {
            state = NpcSoldierState.Chase;
        }
    }
Exemplo n.º 8
0
    private void Update()
    {
        Heading = transform.forward;
        switch (state)
        {
            case NpcSoldierState.Idle:
                break;
            case NpcSoldierState.Follow:
                Follow();
                break;
            case NpcSoldierState.Wander:
                Wander();
                break;
            case NpcSoldierState.Chase:
                Chase();
                break;
        }
        lastState = state;

        if (speechCooldown >= 0f)
        {
            speechCooldown -= Time.deltaTime;
            if (speechCooldown < 0f)
            {
                var sounds = vehicle.GetComponent<SoldierSounds>();
                if (sounds != null)
                {
                    sounds.RandomSpeak();
                    speechCooldown = Random.Range(minSpeechTime, maxSpeechTime);
                }
            }
        }
    }
Exemplo n.º 9
0
 private void SetNoTargetState()
 {
     path = null;
     if (DefaultFollowPlayer)
     {
         state = NpcSoldierState.Follow;
     }
     else
     {
         state = NpcSoldierState.Wander;
         AssignWanderPosition();
     }
 }
Exemplo n.º 10
0
 private void Update()
 {
     Heading = transform.forward;
     switch (state)
     {
         case NpcSoldierState.Idle:
             break;
         case NpcSoldierState.Follow:
             Follow();
             break;
         case NpcSoldierState.Wander:
             Wander();
             break;
         case NpcSoldierState.Chase:
             Chase();
             break;
     }
     lastState = state;
 }