Lelu
Lelu
CC#
Created by Lelu on 8/21/2024 in #help
i was learning about making a top-down game using a tutorial but the player rotation doesnt work
private void FixedUpdate()
{
_smoothedMovementInput = Vector2.SmoothDamp(
_smoothedMovementInput,
_movementInput,
ref _movementInputSmoothVelocity,
0.1f);
_rigidbody.velocity = _smoothedMovementInput * _speed;
RotateInDirectionOfInput();
}

private void RotateInDirectionOfInput()
{
if (_movementInput != Vector2.zero)
{
Quaternion targetRotation = Quaternion.LookRotation(transform.forward, _smoothedMovementInput);
Quaternion rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, _rotationSpeed * Time.deltaTime);

_rigidbody.MoveRotation(rotation);
}
}

private void OnMove (InputValue inputValue)
{
_movementInput = inputValue.Get<Vector2>();
}
}
private void FixedUpdate()
{
_smoothedMovementInput = Vector2.SmoothDamp(
_smoothedMovementInput,
_movementInput,
ref _movementInputSmoothVelocity,
0.1f);
_rigidbody.velocity = _smoothedMovementInput * _speed;
RotateInDirectionOfInput();
}

private void RotateInDirectionOfInput()
{
if (_movementInput != Vector2.zero)
{
Quaternion targetRotation = Quaternion.LookRotation(transform.forward, _smoothedMovementInput);
Quaternion rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, _rotationSpeed * Time.deltaTime);

_rigidbody.MoveRotation(rotation);
}
}

private void OnMove (InputValue inputValue)
{
_movementInput = inputValue.Get<Vector2>();
}
}
somehow its rotating to the opposite direction
4 replies