- Home /
rigidbody.MovePosition is not behaving as it should
Hi
I am working on a moving platform that needs to carry a rigidbody object. I figured rigidbody.MovePosition would work great but apparently not. This is my code:
rig.MovePosition(newPos * moveSpeed * Time.deltaTime);
newPos = Vector3. moveSpeed = float. Doesn't matter if I put this in Update or FixedUpdate, it gives the same result currently. (Yes, I know I should put it in FixedUpdate) So the newPos is set to 10, 0, 3 but it moves to approximately 1.6, 0, 0.5. I have no idea why. There is nothing in the code that sets it to do this.
Now for the rigidbody settings:
Use gravity = false
Is Kinematic = true
Interpolate = Interpolate
Collision Detection = Discrete
Can someone tell me what's wrong and why it does this?
Thanks in advance!
Answer by Positive7 · Jul 30, 2015 at 11:15 PM
Vector3 newPos = new Vector3(10.0f, 0.0f, 3.0f);
float speed = 5.0f;
void FixedUpdate(){
if(rig.position.x <= 10){
Vector3 direction = (newPos - transform.position).normalized;
rig.MovePosition(transform.position + direction * speed * Time.deltaTime);
}
}
Answer by meat5000 · Jul 30, 2015 at 11:45 PM
I'll hazard a guess your moveSpeed is set to 10?
Take newPos.x and assuming you are running at 60FPS
1/60 = 0.016666 = Time.deltaTime
10 * 10 * 0.016666 = 1.6666
For newPos.z
3 * 10 * 0.016666 = 0.49998
You need to specify your current position and add some distance to it. The other answers deal with this but you didnt get an explanation.
Answer by HarutL · Aug 25, 2017 at 08:33 AM
If Your Rigidbody has parent ,then the parents scale should be (1,1,1). And even if it's parent is scaled, if you use Rigidbody.MovePosition(10,0,0)
it will move rigidbody 10 meters in world space you just gonna see different values in Inspector, because of scaled parent.
Your answer
Follow this Question
Related Questions
MovePosition in Rigidbody Ignoring Y axis? 0 Answers
How to make an NPC ball to chase player by rolling, not moving 1 Answer
Rigidbody.MovePosition relativeTo parent 0 Answers
rigidbody.MovePosition in More than One Direction 2 Answers
Rigidbody slightly intrudes another one while pushing it 1 Answer