Jump to content
  • Advertisement
Sign in to follow this  
lucky6969b

Bullet How to avoid physics and AI to dominate over each other?

Recommended Posts

If I set the physics after AI, physics will dominate the final world transformations, which totally erased the world transformations calculated from the AI, or vice versa.
I want to calculate the relative transformation when physics is in effect, how do I do that with btMotionState or derived classes with getWorldTransform overrided?
Thanks
Jack

Share this post


Link to post
Share on other sites
Advertisement

Why is the AI concerned with world transformations? I would think the AI would determine things like picking actions, or what animation to play next...

 

Share this post


Link to post
Share on other sites

If you override transforms after physics you run into the problem that you might break the physics constraints or move into penetration. You can take control over a physics object using ghost objects. A ghost object takes part in the broadphase, but not in the physics simulation. You are responsible for not moving the ghost objects into penetration (e.g. using raycast or volume sweeps).

 

Edited by Dirk Gregorius

Share this post


Link to post
Share on other sites

I assume you are directly modifying position of objects?

If that is the case, you should make the AI set applied force or velocity, for example. Not the position itself. It's a common mistake with many physics engine with broad-phase (engines that will solve the position and angle of objects, the reactions).

Share this post


Link to post
Share on other sites

I don't know how to figure out the forces applied to the object affected....


void AgentMotionState::getWorldTransform(btTransform& worldTrans) const
{

btTransform t;
btDefaultMotionState::getWorldTransform(t);

D3DXMATRIX l_mat;
D3DXMatrixIdentity(&l_mat);
if (m_object)
{
// DX TRANSFORM
l_mat = BT2DX_MATRIX(t);

D3DXVECTOR3 scale, pos;
D3DXQUATERNION quat;

D3DXMatrixDecompose(&scale, &quat, &pos, &l_mat);

Transform* l_transform = m_object->FindComponentByType();

// if setting positions here, the physics will dominate over AI
l_transform->setPosition2(pos);
l_transform->setRotation(quat);

}

// BULLET TRANSFORM
worldTrans = t;

}
Edited by lucky6969b

Share this post


Link to post
Share on other sites

You need to figure out which part of the object is responsible for what actions.  Right now you have physics and AI both trying to move an object around, and that just wont work... clearly.    So, let the physics be responsible for the object's transform and let the AI determine what it wants to do, and then tell the physics system what it wants through setting forces or impulses.

 

9 minutes ago, lucky6969b said:

I don't know how to figure out the forces applied to the object affected....
 

Start with F = ma and work from there.  You should know what mass your objects have, and what speed you want, so just accelerate them until they reach that speed and then set accel back to 0.  Or, if your objects dont need to accelerate, just give them impulses.

Share this post


Link to post
Share on other sites

Okay, When updating AI after the physics, somehow the AI can "overpower" what the physics is trying to do...
and the AI is futile, the physics will take over.
Thanks
Jack

Share this post


Link to post
Share on other sites

But if I let the physics run in its own thread, this has some advantages when I don't update the physics too much by leveraging it some time to sleep,the AI actually has time to counteract with what the physics is currently doing. Because physics is continuous, if I divide the 1.0 with the frame rate, I can get some continuous feel without the physics hogging the world transformations all the time, when the physics thread is sleeping, the AI can do its work now...
Thanks
Jack

Share this post


Link to post
Share on other sites
3 hours ago, lucky6969b said:

But if I let the physics run in its own thread, this has some advantages when I don't update the physics too much by leveraging it some time to sleep,the AI actually has time to counteract with what the physics is currently doing. Because physics is continuous, if I divide the 1.0 with the frame rate, I can get some continuous feel without the physics hogging the world transformations all the time, when the physics thread is sleeping, the AI can do its work now...
Thanks
Jack

I'm not sure I understand, do you still have both the AI and physics setting your object's transforms?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!