- Home /
rigidbody.MovePosition result makes no sense
Using rigidbody.MovePosition for a pathing script but the results that occur make no sense.
Simplified script of the problem
void FixedUpdate()
{
print("position" + rigidbody.position);
rigidbody.MovePosition(new Vector3(-365.0f, 8.9f, 130.0f));
}
Returns this,
position(-365.0, 9.0, 130.0) // Initial position of object before a move
position(-365.0, 9.6, 129.9) // Random? postion after first move
position(-365.0, 8.9, 130.0) // Position it was meant to move to
I can't understand why it flies off to some weird value for 1 iteration then goes to value it's meant to.
-edit-
http://ninjatertle.com/dump/moveposition.unitypackage
Completely empty scene except a camera and 1 rigidbody with a script with the above code. It oscillates on the spot between the correct position and 0.7 higher.
Only thing I can think of is there is something wrong with my exported model.
Answer by Eric5h5 · Jun 01, 2011 at 02:53 AM
If there's nothing in the way and the rigidbody isn't interacting with anything else, it will go to the position specified. Clearly you have some other object(s) it's interacting with. If you want an object to go to a specific position without any collisions, use transform.position and no rigidbody.
Test scene is completely devoid of any other object except a camera. And that script above attached to an object. http://ninjatertle.com/dump/moveposition.unitypackage And yes since my player is a rigidbody I need collisions.
@tertle: your object has an animation on it. Remove the animation.
Doesn't seem to help, but turning on interpolation seemed to fix it. Thanks anyway.
@tertle: Try that script on a Unity primitive to see what I mean. The animation is causing the object to move. Removing the animation will actually fix the problem, ins$$anonymous$$d of just sort of working around it.
I tried on primitives and you're right the issue doesn't occur, but it still doesn't seem to work on the custom mesh, even when I remove the (empty) animation. I have since tried on a few other meshes, square meshes don't seem to have issues but anything with an awkward mesh has an unusual first move. After that the shape moves fine even if I change trajectory.
Answer by tertle · Jun 01, 2011 at 03:21 AM
Turning on interpolation seems to have (pretty much) solved it for me. Very minor jitter around point, but doesn't go opposite direction at start.
Your answer
![](https://koobas.hobune.stream/wayback/20220612093230im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Rigidbody.MovePosition() moves only in the GLOBAL z axis (forward and backward) 1 Answer
How to make rigidbody.AddForce and controller.Move work together? 0 Answers
Moving a GameObject with a script from another GameObject (Rigidbody) 1 Answer
Moving a rigidbody onto exact mouse position using rigidbody.MovePosition? 1 Answer