Moving a Dynamic object

qtsohg
Posts: 14
Joined: Fri Oct 24, 2008 3:32 pm

Moving a Dynamic object

Post by qtsohg »

Hi,

I have the following situation. I have a sphere object, a football as a matter of fact, which is controlled by its own physics algorithm.

Once the ball is out of bounds of the field, I want Bullet to take over.

The problem I am having is that my object is a dynamic object, but I cannot move it around as I need. I managed to move it using:

Code: Select all

btVector3 vTmp = btVector3(tWorldPhysicsData::pvectorTobtVector(m_vPosition));
	btTransform trans;
	trans.getIdentity();
	trans.setOrigin(vTmp);
	if (m_Shape == BT_COLLISION_SPHERE)
	{
		//((btRigidBody*)m_pBTCollisionObject)->getMotionState()->setWorldTransform(trans);
		m_pBTCollisionObject->setWorldTransform(trans);
	}
But when the sphere then falls it falls through the static plane I have set on the floor.

Any help with this? Or any ideas on how I can do this differently.
The main hope is that Bullet can manage the nets for me. Should I rather use a Kinematic object?

Thanks in advance :D
sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York

Re: Moving a Dynamic object

Post by sparkprime »

Why not add the bullet representation of the ball only when you want bullet to simulate it, e.g. when it enters the goal or gets kicked into the crowd.
User avatar
squisher
Posts: 11
Joined: Wed Jul 30, 2008 6:08 pm

Re: Moving a Dynamic object

Post by squisher »

This should do it:

Code: Select all

    btTransform transform;
    rigidBody->getMotionState()->getWorldTransform(transform);
    transform.setOrigin(btVector3(X, Y, Z));  // or whatever
    rigidBody->getMotionState()->setWorldTransform(transform);
    rigidBody->setCenterOfMassTransform(transform);
I agree with sparkprime as well.
peltonen
Posts: 18
Joined: Thu Jan 17, 2008 8:16 pm

Re: Moving a Dynamic object

Post by peltonen »

I am facing a similar issue. Although, with my project, objects fall from the sky and I would like the user to be able to rotate the objects as they fall. Once the objects collide with the ground or another object, they are then out of the user's control.

Is the best way to do this by applying a rotational force to dynamic bodies or should I 'cheat' by making the objects kinetic and applying a constant downward force to them (then swap them out with dynamic bodies when they hit something)?

Do people typically deal with these issues by swapping between two kinds of objects (i.e. kinetic and dynamic)?
User avatar
squisher
Posts: 11
Joined: Wed Jul 30, 2008 6:08 pm

Re: Moving a Dynamic object

Post by squisher »

You can do it either way.

If you want to just flat out *set* the rotation of the object (without interfering with the physics engine), use the code I posted above except replace setOrigin with setRotation.

If you want the user's input to apply a rotational force and let bullet calculate the rest, then either call applyTorque before every stepSimulation, or call applyTorqueImpulse in every InternalTickCallback.

I dont see a reason to swap types in this situation.