public override void SetTarget(Killable value) { target = value; if (value != null) { //Debug.Log("SET TARGET TO: " + value.name); state = NpcSoldierState.Chase; } }
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; } }
private void SetNoTargetState() { path = null; if (DefaultFollowPlayer) { state = NpcSoldierState.Follow; } else { state = NpcSoldierState.Wander; AssignWanderPosition(); } }
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; }
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); } } } }
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; } }
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); } } } }