|
|
|
|
|
|
public class Protagonist : MonoBehaviour |
|
|
|
{ |
|
|
|
[SerializeField] private InputReader _inputReader = default; |
|
|
|
public Transform gameplayCamera; |
|
|
|
public TransformAnchor gameplayCameraTransform; |
|
|
|
|
|
|
|
private Vector2 _previousMovementInput; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void RecalculateMovement() |
|
|
|
{ |
|
|
|
//Get the two axes from the camera and flatten them on the XZ plane
|
|
|
|
Vector3 cameraForward = gameplayCamera.forward; |
|
|
|
cameraForward.y = 0f; |
|
|
|
Vector3 cameraRight = gameplayCamera.right; |
|
|
|
cameraRight.y = 0f; |
|
|
|
if(gameplayCameraTransform.isSet) |
|
|
|
{ |
|
|
|
//Get the two axes from the camera and flatten them on the XZ plane
|
|
|
|
Vector3 cameraForward = gameplayCameraTransform.Transform.forward; |
|
|
|
cameraForward.y = 0f; |
|
|
|
Vector3 cameraRight = gameplayCameraTransform.Transform.right; |
|
|
|
cameraRight.y = 0f; |
|
|
|
//Use the two axes, modulated by the corresponding inputs, and construct the final vector
|
|
|
|
Vector3 adjustedMovement = cameraRight.normalized * _previousMovementInput.x + |
|
|
|
cameraForward.normalized * _previousMovementInput.y; |
|
|
|
//Use the two axes, modulated by the corresponding inputs, and construct the final vector
|
|
|
|
Vector3 adjustedMovement = cameraRight.normalized * _previousMovementInput.x + |
|
|
|
cameraForward.normalized * _previousMovementInput.y; |
|
|
|
movementInput = Vector3.ClampMagnitude(adjustedMovement, 1f); |
|
|
|
movementInput = Vector3.ClampMagnitude(adjustedMovement, 1f); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
//No CameraManager exists in the scene, so the input is just used absolute in world-space
|
|
|
|
Debug.LogWarning("No gameplay camera in the scene. Movement orientation will not be correct."); |
|
|
|
movementInput = new Vector3(_previousMovementInput.x, 0f, _previousMovementInput.y); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//---- EVENT LISTENERS ----
|
|
|
|