public override void OnStateUpdate(CharacterMotor motor, CharacterInput input, Character characterBase) { Transform root = motor.transform; float inputMoveMagnitude = input.worldMotionDirection.magnitude; if (inputMoveMagnitude < CharacterMotor.INPUT_DEADZONE) { inputMoveMagnitude = 0.0f; } root.rotation = Quaternion.Lerp(root.rotation, Quaternion.LookRotation(CameraRig.Instance.FlatSpaceDirection(), Vector3.up), Time.deltaTime * FIRING_TURN_SPEED); motor.MoveMagnitude = Mathf.Lerp(motor.MoveMagnitude, input.worldMotionDirection.magnitude, Time.deltaTime * motor.stats.moveSpeedAcceleration); float oldY = motor.CharacaterRigidbody.velocity.y; Vector3 newVelocity = input.worldMotionDirection.normalized * motor.MoveMagnitude * motor.stats.strafeSpeed; newVelocity.y = oldY; motor.CharacaterRigidbody.velocity = newVelocity; characterBase.RequestQuickFireCalculation(); if (!input.firing) { GameManager.Instance.PushMotorState(motor, ControllerStateID.Locomotion); } }
public override void OnStateUpdate(CharacterMotor motor, CharacterInput input, Character characterBase) { Transform root = motor.transform; Debug.DrawRay(motor.transform.position + Vector3.up, input.worldMotionDirection * 5.0f); float inputMoveMagnitude = input.worldMotionDirection.magnitude; Vector3 targetDir = input.worldMotionDirection; if (inputMoveMagnitude < CharacterMotor.INPUT_DEADZONE) { inputMoveMagnitude = 0.0f; targetDir = root.forward; } motor.MoveMagnitude = Mathf.Lerp(motor.MoveMagnitude, input.worldMotionDirection.magnitude, Time.deltaTime * motor.stats.moveSpeedAcceleration); root.rotation = Quaternion.Lerp(root.rotation, Quaternion.LookRotation(targetDir), Time.deltaTime * motor.stats.turnSpeed * motor.MoveMagnitude); float oldY = motor.CharacaterRigidbody.velocity.y; Vector3 newVelocity = root.forward * motor.MoveMagnitude * motor.stats.moveSpeed; newVelocity.y = oldY; motor.CharacaterRigidbody.velocity = newVelocity; if (input.firing) { GameManager.Instance.PushMotorState(motor, ControllerStateID.Firing); } }
/// <summary> /// The update function called each frame by the character motor, transitions should be handled within the update near the end of the function /// </summary> /// <param name="motor"></param> /// <param name="input"></param> /// <param name="characterBase"></param> public abstract void OnStateUpdate(CharacterMotor motor, CharacterInput input, Character characterBase);