I am facing an strange issue, that when I am moving the character through input reader, the player is moving but the angles are changing on every input. It’s like 0,90,-90 and 180.
Here is the video for more clarity : https://www.youtube.com/watch?v=sP4_qub-fEI
Here is the code of InputReader :
public Vector2 MovementValue { get; private set; }
private PlayerInput playerInput;
private void Start()
{
playerInput = new PlayerInput();
playerInput.Player.SetCallbacks(this);
playerInput.Player.Enable();
}
private void OnDestroy()
{
playerInput.Player.Enable();
}
public void OnLook(InputAction.CallbackContext context)
{
}
public void OnMovement(InputAction.CallbackContext context)
{
MovementValue = context.ReadValue<Vector2>();
Debug.Log($"OnMovement - Movement Value = {MovementValue}");
}
Code of MovementState
public PlayerMovementState(PlayerStateMachine stateMachine) : base(stateMachine)
{
}
public override void Enter()
{
}
public override void Tick(float deltaTime)
{
Vector3 movement = new Vector3();
movement.x = stateMachine.InputReader.MovementValue.x;
movement.y = 0;
movement.z = stateMachine.InputReader.MovementValue.y;
Debug.Log($"Tick({deltaTime}), movement = {movement}, adjusted movement = {movement * stateMachine.MovementSpeed * deltaTime}");
stateMachine.Controller.Move(movement * stateMachine.MovementSpeed * deltaTime);
if (stateMachine.InputReader.MovementValue == Vector2.zero) { return; }
stateMachine.transform.rotation = Quaternion.LookRotation(movement);
}
public override void Exit()
{
}