New to Bullet - 2 questions

ChampiAtomik

01-12-2009 08:12:23

Hello,

I used Bullet recently to add physics in my project.

I have a character controller, and I want him to hold a weapon. I created a box shape, but I don't know how to link it with the hand of the character.

I think I have to use the hand bone and a constraint ?

I also have a character controller representing the enemy, but they don't collide each other with the hero, how can I do that ? I want them to stop when they collide.

Can someone help me please ?

Thanks

Fish

01-12-2009 21:12:15

Hello,

I used Bullet recently to add physics in my project.

I have a character controller, and I want him to hold a weapon. I created a box shape, but I don't know how to link it with the hand of the character.

I think I have to use the hand bone and a constraint ?

I also have a character controller representing the enemy, but they don't collide each other with the hero, how can I do that ? I want them to stop when they collide.

Can someone help me please ?

Thanks


For your first question you can try the google search feature in the Ogre Forums with the search term 'attach node to bone'.

Someone else will have to help you with the second question. Maybe try searching the Bullet Forums?

-Fish

ChampiAtomik

01-12-2009 21:26:17

Hi, thanks to your answer.

I already attached the weapon to a bone and got a tagpoint, but i wanted to link them physically, because with this method the shape doesn't follow the movement and then it can't collide =S

I think I need something like joint or constraint ?

For the second question I already posted it on the bullet forum ^^

Fish

02-12-2009 14:05:16

I'm not sure that using a physics shape for the sword is the best approach. But I think in order for that to work you would need to manually update the world transform for the swords physics shape each frame, I'm not sure how to do this automatically.

Another approach might be using bullets ray cast system instead of a physics shape. Set up two nodes to represent the business end of the sword, cast a ray between the nodes each frame, and if it hit a physics object then collect information about the object and do whatever magic you need.

Just a couple thoughts. I'm sure there are better approaches.

-Fish

ChampiAtomik

02-12-2009 16:39:11

Thanks to your answer, I didn't know I can did with this method, I'll try it, I don't have any answer on bullet's forum...

Edit : Now that I have the two nodes as you said, I don't know how to manage a raycast between two node. I checked the API and a ray is only defined by an origin and a direction, not an origin and an end or a distance

Edit2 : I guess I have to use the distance of the result

ChampiAtomik

09-12-2009 23:13:05

Someone on the main ogre forum told me to use a physic library to do the collisions of the weapon.

Any idea to link the weapon to the hand of the character and perform collisions ?

Thanks

Fish

10-12-2009 14:37:35

In the code you posted you are trying to use an Ogre::RaySceneQuery. My suggestion was to try using "bullets ray cast system", not Ogres. Look up btCollisionWorld::ClosestRayResultCallback. You could probably use it like this:


bool MyCollisionClass::didMySwordHitAPhysicsObject()
{
// Get the world position of the node at the base of the sword.
Ogre::Vector3 baseNodeWorldPos = mSwordBaseNode->_getDerivedPosition();

// Convert the Ogre::Vector3 to a btVector3
btVector3 btBaseNodeWorldPos (baseNodeWorldPos .x, baseNodeWorldPos .y, baseNodeWorldPos .z);

// Get the world position of the node at the point of the sword.
Ogre::Vector3 pointNodeWorldPos = mSwordPointNode->_getDerivedPosition();

// Convert the Ogre::Vector3 to a btVector3.
btVector3 btPointNodeWorldPos (pointNodeWorldPos .x, pointNodeWorldPos .y, pointNodeWorldPos .z);

// Initialize the callback object.
btCollisionWorld::ClosestRayResultCallback rayCallback(btBaseNodeWorldPos, btPointNodeWorldPos );

// Shoot the ray.
mBulletCollisionWorld->rayTest(btBaseNodeWorldPos , btPointNodeWorldPos , rayCallback);

// rayCallback contains info about the object that was hit. Return the information that you need.
if(rayCallback.m_closestHitFraction < 1.0)
{
return true;
}

return false;
}


-Fish

ChampiAtomik

10-12-2009 16:43:09

Omg thank you, I forgot the "_getDerivedPosition()" function, I couldn't have the correct direction because I only used "getPosition()" which is not the world position.

Now it works with the Ogre::raySceneQuery, I'll try your solution later, I think it's more precise

Thank you