/// <summary> /// makes the npc move. /// </summary> public void ApplyMovementForce() { float maxSpeed = 0.0f; float magnitude = rigidbody.velocity.magnitude; switch (myState) { case NPCSTATE.COMBAT: maxSpeed = NPCRUNSPEED; myAnim = NPCANIMATIONS.RUN; speedMagnitude = (magnitude / NPCRUNSPEED) * 0.8f; // Always run. break; case NPCSTATE.FOLLOW: if (!friendlyTarget) { maxSpeed = NPCWALKSPEED; speedMagnitude = (magnitude / NPCWALKSPEED) * 2.2f; myAnim = NPCANIMATIONS.WALK; } else if (Vector3.Distance(friendlyTarget.transform.position, transform.position) < NPCFOLLOWWALKDIST) { maxSpeed = NPCWALKSPEED; speedMagnitude = (magnitude / NPCWALKSPEED) * 2.2f; myAnim = NPCANIMATIONS.WALK; } else { maxSpeed = NPCRUNSPEED; myAnim = NPCANIMATIONS.RUN; speedMagnitude = (magnitude / NPCRUNSPEED) * 0.8f; } break; case NPCSTATE.ROAM: maxSpeed = NPCWALKSPEED; speedMagnitude = (magnitude / NPCWALKSPEED) * 2.2f; myAnim = NPCANIMATIONS.WALK; break; } if (magnitude < maxSpeed) { Vector3 mDir = movementDirection; mDir.y = 0.0f; mDir = mDir.normalized; rigidbody.AddForce(mDir * NPCACCELERATIONSPEED); } }
public override void Death() { myAnim = NPCANIMATIONS.DEATH; myState = NPCSTATE.DEATH; if (collider) { DestroyImmediate(collider); } if (rigidbody) { DestroyImmediate(rigidbody); } if (animation["death"].time > animation["death"].length + NPCTIMEBEFOREDOWNED) { // Start falling through ground. 2 units? transform.position += (Vector3.down * Time.deltaTime) * NPCDEATHDOWNSPEED; Destroy(gameObject, 3.0f); } }
public bool GroundCheck() { if (Physics.Raycast(transform.position, Vector3.down, 0.2f, ignoreSightLayer)) { if (!grounded) { AnimateOnce("jump"); } if (!applyMovementForce) { myAnim = NPCANIMATIONS.IDLE; } return(true); } else { myAnim = NPCANIMATIONS.MIDAIR; return(false); } }
public override void Death() { myAnim = NPCANIMATIONS.DEATH; myState = NPCSTATE.DEATH; if (collider) DestroyImmediate(collider); if (rigidbody) DestroyImmediate(rigidbody); if (animation["death"].time > animation["death"].length + NPCTIMEBEFOREDOWNED) { // Start falling through ground. 2 units? transform.position += (Vector3.down * Time.deltaTime) * NPCDEATHDOWNSPEED; Destroy(gameObject, 3.0f); } }
public bool GroundCheck() { if (Physics.Raycast(transform.position, Vector3.down, 0.2f, ignoreSightLayer)) { if (!grounded) AnimateOnce("jump"); if (!applyMovementForce) myAnim = NPCANIMATIONS.IDLE; return true; } else { myAnim = NPCANIMATIONS.MIDAIR; return false; } }