SetGlobalOrientation Adds Velocity Towards Orientation

kurisusan

11-06-2010 11:38:36

Hi I am having an issue where I reorientate an body (call it bodyA) every frame to look at the closest body to it (call it bodyC).

I get the location of the closest body and set the orientation to its current location. This works fine, however when the next frame starts and the advance method is called on the timecontroller, I noticed that the linear velocity of bodyA starts to increase and bodyA starts to slowly move to bodyC. Every frame the linear velocity increase by a small amount. If I stop reorientating bodyA towards its closest body though the velocity is set back to 0.

Has anyone ever encountered this before? Is it something to do with how setGlobalOrientation works?

Please any help would be much appreciated.

betajaen

11-06-2010 12:04:54

Hmm, weird. I assume the Body is on a plane or a triangle mesh?

When you set the Global Orientation you are literally "teleporting" the object into that new orientation. Think of it as you suddenly switching directions when your walking, the time you take to switch directions is zero. Freaky really. PhysX isn't really expecting that, you wouldn't in reality either.

Anyway; Two things I can think of:

- The object is acting like a wheel on it's side, the PhysX is translating that into linear motion.
- Inprecision of the floats in the Quaternion causes the object to be slightly partly inside the plane. Causing it to jump out in the next frame, causing your movement.

It's probably neither; however calling setLinearVelocity(0,0,0) on it continuously would stop the movement. But I would suggest you use a more safer and realistic way of turning the body.