public void DontMoveWithAgent(AIBrain ai) { NavMeshAgent agent = ai.Agent; if (agent) { Transform transform = ai.Transform; Animator animator = ai.Animator; agent.destination = ai.Transform.position; bool turnedMovement = false; if (shouldTurnToPosition) { agent.updateRotation = false; turnedMovement = true; switch (turnToType) { case ET.TurnToType.ToCurrentTarget: turnToPosition = ai.GetCurrentTargetPos(); break; case ET.TurnToType.ToPosition: // already set in function break; default: break; } } else { agent.updateRotation = true; turnedMovement = false; } #region Unity Manual Code Vector3 worldDeltaPosition = agent.nextPosition - transform.position; // Map 'worldDeltaPosition' to local space float dx = Vector3.Dot(transform.right, worldDeltaPosition); float dy = Vector3.Dot(transform.forward, worldDeltaPosition); Vector2 deltaPosition = new Vector2(dx, dy); // Low-pass filter the deltaMove float smooth = Mathf.Min(1.0f, Time.deltaTime / 0.15f); smoothDeltaPosition = Vector2.Lerp(smoothDeltaPosition, deltaPosition, smooth); // Update velocity if delta time is safe if (Time.deltaTime > 1e-5f) { velocity = smoothDeltaPosition / Time.deltaTime; } bool shouldMove = velocity.magnitude > 0.1f && agent.remainingDistance > agent.radius; // Move agent to transform if (worldDeltaPosition.magnitude > agent.radius) { agent.nextPosition = transform.position + 0f * worldDeltaPosition; } // Set transform's y to agent transform.position = new Vector3(transform.position.x, agent.nextPosition.y, transform.position.z); #endregion Unity Manual Code Vector3 desiredDir = (-transform.position + new Vector3(agent.nextPosition.x, transform.position.y, agent.nextPosition.z)).normalized * 2; float angle = 0; if (turnedMovement) { angle = Vector3.Angle(transform.forward, (turnToPosition - transform.position).normalized); angle = angle * Mathf.Abs(Vector3.Dot(transform.right, (turnToPosition - transform.position).normalized)); transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(-transform.position + new Vector3(turnToPosition.x, transform.position.y, turnToPosition.z)), Time.deltaTime * moveProps.idleTurnToSmooth); } float speedAnim = Vector2.SqrMagnitude(new Vector2(ai.Animator.GetFloat("VelX"), ai.Animator.GetFloat("VelY"))); if (turnedMovement) { if (speedAnim < moveProps.legsStopTurnAtSqrM && Mathf.Abs(angle) > moveProps.legsStartTurnAtAngle) { ai.Animator.SetFloat("LegsAngle", angle * moveProps.legsTurnAngleMult, moveProps.legsTurnAngleDamp, Time.deltaTime); ai.Animator.SetBool("LegTurn", true); ai.GetStateSystem <AIStateSystemAnimator>().EnableLayer(ai, 3, true, true); } else { ai.Animator.SetFloat("LegsAngle", 0, moveProps.legsTurnAngleDamp, Time.deltaTime); ai.Animator.SetBool("LegTurn", false); ai.GetStateSystem <AIStateSystemAnimator>().DisableLayer(ai, 3, true, true); } } else { ai.Animator.SetFloat("LegsAngle", 0, moveProps.legsTurnAngleDamp, Time.deltaTime); ai.Animator.SetBool("LegTurn", false); ai.GetStateSystem <AIStateSystemAnimator>().DisableLayer(ai, 3, true, true); } Quaternion refShift = new Quaternion(transform.rotation.x, transform.rotation.y * -1f, transform.rotation.z, transform.rotation.w); Vector3 moveDirection = refShift * desiredDir; float locomotionDamp = moveProps.velocityAnimDamp; ET.MoveType moveType = ET.MoveType.Walk; float velocityLimit = moveProps.animatorWalkSpeed; switch (moveType) { case ET.MoveType.Walk: velocityLimit = moveProps.animatorWalkSpeed; agent.speed = moveProps.agentWalkSpeed; agent.angularSpeed = moveProps.agentAngularSpeedWalk; break; case ET.MoveType.Run: velocityLimit = moveProps.animatorRunSpeed; agent.speed = moveProps.agentRunSpeed; agent.angularSpeed = moveProps.agentAngularSpeedRun; break; case ET.MoveType.Sprint: velocityLimit = moveProps.animatorSprintSpeed; agent.speed = moveProps.agentSprintSpeed; agent.angularSpeed = moveProps.agentAngularSpeedSprint; break; default: break; } float xVelocity = moveDirection.x, yVelocity = moveDirection.z; // Limit velocity if (xVelocity > 0) { xVelocity = xVelocity > velocityLimit ? velocityLimit : xVelocity; } else if (xVelocity < 0) { xVelocity = -xVelocity > velocityLimit ? -velocityLimit : xVelocity; } if (yVelocity > 0) { yVelocity = yVelocity > velocityLimit ? velocityLimit : yVelocity; } else if (yVelocity < 0) { yVelocity = -yVelocity > velocityLimit ? -velocityLimit : yVelocity; } if (!shouldMove) { xVelocity = 0; yVelocity = 0; } animator.SetFloat("VelX", xVelocity, locomotionDamp, Time.deltaTime); animator.SetFloat("VelY", yVelocity, locomotionDamp, Time.deltaTime); animator.SetFloat("CrouchStand", Mathf.Clamp01(Mathf.Lerp(animator.GetFloat("CrouchStand"), crouching ? 0 : 1, Time.deltaTime * moveProps.crouchStandSmooth))); } }
public override void Activate(AIBrain ai) { ai.GetStateSystem <AIStateSystemWeapon>().ReloadWeapon(ai); }
public override void DeActivate(AIBrain ai) { infoDangerEx.IsBeingUsedByAction = false; ai.GetStateSystem <AIStateSystemLookAt>().StopLooking(ai); }
public override bool IsCompleted(AIBrain ai) { return(ai.GetStateSystem <AIStateSystemWeapon>().IsMeleeHitEnded(ai)); }
public override void Activate(AIBrain ai) { ai.GetStateSystem <AIStateSystemAnimator>().AnimateTrigger(ai, "Dodge", false, false, "", "Locomotion", 0); ai.GetStateSystem <AIStateSystemAnimator>().AnimateFloat(ai, "Angle", infoDodge.angle.Value, false, false, "", "Locomotion", 0); }
public override void DeActivate(AIBrain ai) { ai.GetStateSystem <AIStateSystemMove>().StopTurning(ai); base.DeActivate(ai); ai.WorldState.SetKey(DS.atSafePosition, false); }
public override void Activate(AIBrain ai) { ai.GetStateSystem <AIStateSystemWeapon>().HitMelee(ai); ai.GetStateSystem <AIStateSystemAnimator>().DisableLayer(ai, 1, false, false); }
public override bool IsCompleted(AIBrain ai) { return(ai.GetStateSystem <AIStateSystemMove>().ReachedDestination(ai, .07f)); }
public override void Activate(AIBrain ai) { base.Activate(ai); ai.GetStateSystem <AIStateSystemMove>().SetTurnToPosNStartTurn(ai, ET.TurnToType.ToCurrentTarget); }
public override bool WeaponAimingFinished(AIBrain ai) { return(ai.stateSystemAnimator.IsStartedAnimationFinished("", "ReadyIdle") && ai.GetStateSystem <AIStateSystemLookAt>().GetHeadIKWeight() > .8f); }
public override void Activate(AIBrain ai) { ai.GetStateSystem <AIStateSystemMove>().SetMoveToPositionNStartMove (ai, ET.MoveType.Run, ET.MoveToType.ToPosition, safeInfo.safePosition.Value); }
virtual public void OnIsHandAwayFromGun(AIBrain ai) { ai.CurrentWeapon.SetParent(null); ai.CurrentWeapon.position = new Vector3(0, -500, 0); ai.GetStateSystem <AIStateSystemAnimator>().DisableLayer(ai, 1, true, false); }
public override void Activate(AIBrain ai) { ChangePatrolPoint(); ai.GetStateSystem <AIStateSystemMove>().SetMoveToPositionNStartMove( ai, ET.MoveType.Walk, ET.MoveToType.ToPosition, patrolPoints[currentIndex]); }
public override void GeneralPostEffects(AIBrain ai) { ai.GetStateSystem <AIStateSystemMove>().StopMoving(ai); base.GeneralPostEffects(ai); }
public override void DeActivate(AIBrain ai) { ai.GetStateSystem <AIStateSystemMove>().StopMoving(ai); }
public override void Activate(AIBrain ai) { ai.GetStateSystem <AIStateSystemMove>().SetMoveToPositionNStartMove (ai, ET.MoveType.Run, ET.MoveToType.ToCurrentTarget); }