Sign in to follow this  
Quat

collision and messages

Recommended Posts

I'm trying to keep my collision system agnostic to the objects. The collision system gets enough input to determine a collision and then sends a collision message to the two objects involved with the collision info so that they can respond. My problem is that the objects respond differently based on the object collided with. For example, if the player hits a wall, he will just stop/slide, but if a rocket hits the player, he needs to take damage and get pushed back. I'm trying to figure out how to handle this nicely. A simple way would be to flag objects as damaging causing on collision: if( object.isDamageCausing() ) take damage/push back else // just stop or try to slide around object stop/slide Any other ideas?

Share this post


Link to post
Share on other sites
Use a "physical world", it need not be especially accurate but will control objects, apply forces, stop them etc. according to set rules. This is done in the "collision-engine". Then you send messages to both objects where you perhaps also include a pointer of the other object. Each object will response to the collision (sounds, visuals etc) but will not need to bother about their posision since this has allready been handled by the world physics (they would also be able to apply additional forces on the colliding object depending on their nature). Don't know if this is the best of ways but I've used this in a shootemup and it works well.

Share this post


Link to post
Share on other sites
The way you have described is sound and generally how it is done in the many various collision engines. I would reconsider what you report something a little more generic than damage causing is likely to be more suitable. Another common report is the collision material. With this you could then query against materials

void Object::CollisionMessage(CMessage* pMessage)
{
// I collided with pMessage->pOther
switch (pMessage->materialID)
{
case MATERIAL_DAMAGE:
TakeDamagePushBack(); break;
default:
WhateverElse();
}
}

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