- Home /
How do I implement both Rigidbody.MovePosition and Rigidbody.MoveRotation simultaneously?
I'm trying to create a platform (with a rigid body) that moves upwards infinitely while rotating about the z-axis at a certain speed. In order to make the platform move upwards infinitely, I've used:
rb.MovePosition(transform.position + transform.up * Time.deltaTime * speed); //rb is Rigidbody
This seems to work fine. Now I'm trying to making it rotate while moving upwards in order to make the game more difficult for the player. I've been looking through the manual and I've been using rb.MoveRotation in various different ways but none of them are working. Is there a way I can add rb.MoveRotation to this code such that the platform rotates about the z-axis while moving upwards at the same time?
For the record, Is Kinematic is set to true because I don't want other objects to affect the movement of the platform.
Answer by gribbly · May 25, 2016 at 06:36 PM
Just put them one after the other, something like:
rb.MovePosition(transform.position + transform.up * Time.deltaTime * speed); //rb is Rigidbody
rb.MoveRotation(rb.rotation * deltaRotation);
Details on parameters for MoveRotation are here:
http://docs.unity3d.com/ScriptReference/Rigidbody.MoveRotation.html
This only works if I set eulerAngleVelocity to (0,360,0). It doesn't work when I set eulerAngleVelocity to (0,0,360). The platform just rotates about the z-axis but doesn't move upwards,
This won't work. Only the first active one of the two would actually execute. If $$anonymous$$ovePosition
if executing, then $$anonymous$$oveRotation
won't fire until the next frame the other one has stopped, and vice versa.