C
C#4mo ago
Lelu

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
3 Replies
Pobiega
Pobiega4mo ago
More of a question for $unity than us to be honest
Lelu
LeluOP4mo ago
alr ty
Want results from more Discord servers?
Add your server