Proper way to force positions and rotations?

daBrado
Posts: 11
Joined: Thu Oct 05, 2006 10:41 am

Proper way to force positions and rotations?

Post by daBrado »

Hi,

I was curious, what is the proper way to force the position and/or rotation of a rigid body?

For example, let's imagine a game of 3d pong. So, let's say I have a computer controlled paddle that tracks and strikes a ball. But, I don't want the paddle to start rotating once it strikes the ball. I want to keep the paddle always at the same rotation. Should I be manually setting its worldTransform to the proper rotation? Or should I use a constraint, and lock the paddle's rotation degrees of freedom? Or is there another option?

Also, let's say the ball should be reset to a home position if it misses the paddle and goes out of bounds. Should I reset its position via btRigidBody->setWorldTransform()? Or though its btMotionState->setWorldTransform()? Or something else? In other words, what is the best way to "teleport" an object to another location, without bullet trying to interpolate the path or assign a velocity to the body, etc?

Thanks for any help,
Braden
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Proper way to force positions and rotations? (kinematic)

Post by Erwin Coumans »

A paddle is a kinematic/animated object.

Bullet has support for that by creating a static object, and setting its collisionflags as kinematic, and disable deactivation(sleep):

Code: Select all

body->setCollisionFlags( body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
body->setActivationState(DISABLE_DEACTIVATION);
See CcdPhysicsDemo for an example: enable USE_KINEMATIC_GROUND and see the ground move, while the stack of cylinders gets moved by it.

Recommended is to use a btMotionState derived class, then Bullet will get the kinematic transform from the motionstate each frame and derive linear/angular velocity for the kinematic animated object, so it interacts properly (one-way) with dynamic rigidbodies.


daBrado wrote:Hi,

I was curious, what is the proper way to force the position and/or rotation of a rigid body?

For example, let's imagine a game of 3d pong. So, let's say I have a computer controlled paddle that tracks and strikes a ball. But, I don't want the paddle to start rotating once it strikes the ball. I want to keep the paddle always at the same rotation. Should I be manually setting its worldTransform to the proper rotation? Or should I use a constraint, and lock the paddle's rotation degrees of freedom? Or is there another option?

Also, let's say the ball should be reset to a home position if it misses the paddle and goes out of bounds. Should I reset its position via btRigidBody->setWorldTransform()? Or though its btMotionState->setWorldTransform()? Or something else? In other words, what is the best way to "teleport" an object to another location, without bullet trying to interpolate the path or assign a velocity to the body, etc?

Thanks for any help,
Braden
daBrado
Posts: 11
Joined: Thu Oct 05, 2006 10:41 am

Re: Proper way to force positions and rotations? (kinematic)

Post by daBrado »

Erwin Coumans wrote:A paddle is a kinematic/animated object.

Bullet has support for that by creating a static object, and setting its collisionflags as kinematic, and disable deactivation
Ideally, I'd like to move the paddle around by changing its velocity to move towards a target position. However, I can't set the velocity of a static object, even if kinematic.

Must I manually calculate the transforms along the desired path of the paddle, i.e. do velocity transformations manually....? If so, why?
Erwin Coumans wrote:Recommended is to use a btMotionState derived class, then Bullet will get the kinematic transform from the motionstate each frame and derive linear/angular velocity for the kinematic animated object, so it interacts properly (one-way) with dynamic rigidbodies.
I'm afraid I don't understand what you mean by this. Are you talking about a btMotionState on the paddle...? A static kinematic object can set its linear/angular velocity implicitly via the motion state, but I cannot set them explicitly via setLinearVelocity() and setAngularVelocity() ?

Thanks for any help,
Braden