- Home /
transform.rotation cancels movement.
So I have this code:
void Move(float h, float v)
{
movement.Set(h, 0f, v);
movement = movement.normalized * movementSpeed * Time.deltaTime;
rb.MovePosition(transform.position + movement);
}
and it works perfectly fine, but when I have this running:
if (movement != Vector3.zero)
{
transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(movement), rotationSpeed *Time.deltaTime);
}
then my movement code works with a delay, waits for the gameObject to turn, the weirdest thing is the fact that this code worked perfectly fine in 2017.1
Comment
I see you use a rigidbody function "$$anonymous$$ovePosition" to adjust the position of the object, but access the transform directly to change the rotation.
I'd recommend using the rigid body function $$anonymous$$oveRotation for consistency. Not sure if this will actually resolve your issue: just a shot in the dark.
Best Answer
Answer by Witherik · Mar 24, 2018 at 05:28 PM
Using this:
rb.MoveRotation(Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(movement), rotationSpeed * Time.deltaTime));
instead, works normal.
Your answer
![](https://koobas.hobune.stream/wayback/20220612155303im_/https://answers.unity.com/themes/thub/images/avi.jpg)