x


transform.Translate vs rigidbody.MovePosition?

Okay, here's a REAL noob question for you...

Which of the above should I be using for my race car? It's a VERY basic retro -styled game and I have it working perfectly with transform.Translate/rotate but the collision seems a little odd. I read somewhere that if you want the objects to collide, you should use rigidbody.MovePosition? Is this true? And if so... why is this? Also, I want my game to be able to run on low end hardware... which of the two methods produces the least CPU overheads?

Unfortunately, the Unity scripting reference just didn't answer my questions...

Cheers!

more ▼

asked Feb 08 '12 at 07:11 PM

POLYGAMe gravatar image

POLYGAMe
434 37 46 53

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

The reason why it is recommended to use MovePosition is because when the rigid body is NOT kinematic, an extra step is taken into account when calculating how the rigid body reacts to physics. Since the transform has nothing to do with physics, it is just the coordinate information of the NON physics based components of the Game Object, this causes variation between the two bodies.

Now MovePosition takes this into effect and more properly handles your transform information along with your rigid body information.

When you think about it, when translating the transform and not the rigid body itself in the case of NON-kinematic bodies, the rigid body information is thus calculated at the end of the physics step frame, causing a slight difference in the two positions of each body. It's pretty much the same thing if you translate the position of the rigid body using

rigidbody.position

or anything of the like. MovePosition was made specifically to deal with this oscillation of the two bodies in conjunction with active physics. CPU overhead is negligible in this case, since MovePosition was made specifically for this purpose.

more ▼

answered Feb 08 '12 at 08:10 PM

dannyskim gravatar image

dannyskim
3.9k 5 7 19

Ah, okay, thanks! So in my case, I can probably get away with transform.Translate, as I don't need physics, so much, just need to change speed when objects touch, as it is a 2.5D game, I am using planes with sprites mapped to them, but have cubes as the collision zones...

Am I right in that thinking?

Feb 08 '12 at 09:59 PM POLYGAMe

Well the slight difference in calculation between the two may provide a chance for the Unity Engine to report inaccurate collisions when recalculating the rigid body's position and collider information. If accurate collisions is your concern, then I would suggest using MovePosition as recommended.

Feb 09 '12 at 12:08 AM dannyskim

Yeah, you're right. I'm finding that with transform.Translate, I can make the trees adjust my car's speed when there is a crash, but then it keeps driving through them. I'm changing the control script now. Thanks for your help!

Feb 09 '12 at 12:35 AM POLYGAMe
(comments are locked)
10|3000 characters needed characters left

Sorry guys but isn't rigidbody.MovePosition meant to be used on kinematic rigid bodies? If I well understood the PhysX philosophy, the only way you should move a rigid body is to apply a force.

more ▼

answered Feb 13 '12 at 06:35 PM

neuropanic gravatar image

neuropanic
1 1 2 2

I think you're right, but I've never used MovePosition before so there may very well be applications for it outside of kinematics, like if you want something to move but don't want it to be affected by momentum.

Feb 13 '12 at 07:14 PM Jason B

Interesting.. I will try to test the difference! If it's really the case will be really useful for me. Thanks :)

Feb 13 '12 at 07:31 PM neuropanic

Should set force for RBs. And setting velocity directly can handle almost anything, such as momentum & faking friction.

MovePosition seems to be for special cases where you know where you want it be be. Maybe following a motion curve (and blasting things out of the way.) You can set velocity and aim yourself along the tangent, but MovePosition is better.

Feb 13 '12 at 08:16 PM Owen Reynolds

Cool, I'll have a play. I'm still using transform.Translate at the mo, as I found a workaround, but I might try out addforce.

Feb 13 '12 at 08:33 PM POLYGAMe
(comments are locked)
10|3000 characters needed characters left

Hi Owen, so you already used MovePosition? No issues with complex hierarchy?

more ▼

answered Feb 13 '12 at 11:00 PM

neuropanic gravatar image

neuropanic
1 1 2 2

I just tested MovPos some and decided velocity was better. MovPos is glitchy if you stay in contact. Tried these lines, with some child platforms and an unattached RB cube resting on one:

//rigidbody.MovePosition(SS+Vector3.up*Time.time);
rigidbody.velocity=Vector3.up;

Both move up at a speed of 1M/S, but MovePos makes the cube on top bobble and eventually fall through. Even resting on the parent, I got some bobbling.

Feb 14 '12 at 01:46 AM Owen Reynolds
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1370
x41
x1

asked: Feb 08 '12 at 07:11 PM

Seen: 5768 times

Last Updated: Feb 14 '12 at 01:46 AM