I posted something similar a while back, and the answer I got (which was to put it in fixedUpdate) helped the problem a lot, but not completely. When I use Rigidbody.MovePosition or Rigidbody.MoveRotation, the object doesn’t always move the correct distance. Sometimes it’ll move a little farther than it should, or rotate too far around. Does anybody know what may be wrong? Here’s my code, thanks for the help!
if(bIsSpinning == true)
{
if(spinDirection == "right")
{
rigidbody.MovePosition(rigidbody.position + Vector3(30,0,0) * Time.fixedDeltaTime);
rigidbody.MoveRotation(rigidbody.rotation * Quaternion.Euler(Vector3(0,360,0) * Time.fixedDeltaTime));
}
else if(spinDirection == "left")
{
rigidbody.MovePosition(rigidbody.position + Vector3(-30,0,0) * Time.deltaTime);
rigidbody.MoveRotation(rigidbody.rotation * Quaternion.Euler(Vector3(0,360,0) * Time.fixedDeltaTime));
}
if(spinDirection == "up")
{
rigidbody.MovePosition(rigidbody.position + Vector3(0,20,0) * Time.fixedDeltaTime);
}
else if(spinDirection == "down")
{
rigidbody.MovePosition(rigidbody.position + Vector3(0,-20,0) * Time.fixedDeltaTime * 3);
}
else
{
}
}