Sign in to follow this  

Where to test for collision.

This topic is 2662 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have player, enemy and game classes. Both the player and enemy classes are mostly the same, the both contain animations and bounding spheres. The player class' animations are triggered using the keyboard. The next step for me is to trigger the animation on the enemy when it is struck by the player's punch. My idea is to check to see if the punch animation is playing, and if the player's hand intersects with the enemy's head.
The trouble I'm having is where do I perform this check? Whatever class I do it in needs to tell the enemy to play the 'getting hit' animation, and the same for the player class when I implement it there. Is my best bet to have an entirely separate class for collision? Then how do I pass the collision events back to the class that needs to know, and how would the receiving class handle it?
This problem's been a bit of a head-scratcher, and I could use some help.

Share this post


Link to post
Share on other sites
You're got a complicated scenario on your hands. Checking for collsions between animated meshes is tricky in any case, and you're looking for a specific collision.

One approach might be to implement a collision detection function in the enemy class (and in the player class if you're looking for potential collisions there, also). Because sphere collisions are easiest, the function could be something like

bool Enemy::SphereCollide(vector3 spherePosition, float sphereRadius)
{
// check for collision with whatever position or bone, etc., you want
return collision_found;
}

The Enemy class need not know anything about other classes.

Since you're looking for very specific collisions and specific responses, a separate Collision class is a possibility. That class would have to have access to the player's bone positions, either directly or through a function call such as a player class function

vector3 GetBonePosition(int boneNumber);


It might get pretty convoluted to try to generalize with a virtual base class for all the actors but it depends on your future needs.

Share this post


Link to post
Share on other sites
Do you use an event system at all? Where ever you decide to put it, when a collision is detected it should send an event "collision occured". Which can be picked up by whoever needs it (player/enemy) who will then deal with it as they need (play hit animation).

I am using physX/Ogre3D and how I would do it is probably like this. I would have a shpere as a fist and a shpere as the head. I just play animations as normal (which move the fist/head etc). I don't have to sworry about checking for collisions but if one occurs then a callback function will be called by physx with information about the collision. From that information I could determine that players fist hit enemys head. I'd then dispatch a message to the enemy/whoever else is listening saying "EnemyXYZ got hit in the head by Player". The enemy would pick it up and do "Play animation hit in head". Maybe you have somehting where damage numbers float off, in which case that system could also listen for the message and react accordingly.

Share this post


Link to post
Share on other sites
Quote:
Original post by dirtysteve
Quote:
Original post by GregMichael
Have a look at the Bullet Physics SDK


Have you used it? Do you know how it compares to the other SDk's like JigLibx?



Yes guy :)
In my opinion the physx is the best

Share this post


Link to post
Share on other sites

This topic is 2662 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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