Page 1 of 1

Collision event for fireball

Posted: Wed May 04, 2011 10:09 pm
by limeh
Hi, I'm trying to make a fireball that will explode/get removed when it collides with anything. I used DetectingInitialCollision event to handle the collision event. I've successfully made it remove itself when it collides however, how do i make it so that it wont collide with the caster who summoned the spell? My caster is a box entity with a skinned model attached to it(as taught a few post before). I tried adding a tag onto the box and used a condition check of "if((string)otherEntityInformation.Entity.Tag == "firemage")" but it causes the game to crash whenever the collision event happens. My guess is because i'm using a static mesh ( same as the gettingstarteddemo ) as my terrain and that has no tags. If that is the problem, how do i add a tag to it since its not an entity?

Please help, thank you so much

Re: Collision event for fireball

Posted: Wed May 04, 2011 11:03 pm
by Norbo
Collision rules would be the best bet. They allow you to customize the interaction between two objects to disallow stages of the pipeline. More information and a sample can be found here: http://bepuphysics.codeplex.com/wikipag ... umentation

While you won't have to use the tags for this, here's a bit of info about them: Entities have tags, as you've noticed, but so do BroadPhaseEntries. The BroadPhaseEntry class is the superclass of all Collidables like StaticMesh and EntityCollidable (the thing in the entity.CollisionInformation property). Sometimes, setting the BroadPhaseEntry tag is a more direct solution that avoids having to use entity tags.

Also, I would recommend not removing anything from the space within DetectingInitialCollision handlers. That event is executed in-line from a possibly multithreaded context. Removing an object from the space from there without some thread-safe buffering will inevitably cause a crash or bug of some kind. I would recommend that you use the InitialCollisionDetected version of the event, which is 'deferred' and occurs at the end of the frame from a sequential, safe context. Entities can be removed from the space within deferred event execution.

More information about events can be found here: http://bepuphysics.codeplex.com/wikipag ... umentation
The rule is that present tense '-ing' events are 'immediate' and execute in-line, while past tense '-ed' events are deferred.

Re: Collision event for fireball

Posted: Thu May 05, 2011 6:11 pm
by limeh
I used InitialCollisionDetected initially but when the collision of the fireball entity collides with the static mesh, the game crashes. It highlights the error on my space.update(); . Why is that the case?

Also, i tried playing around with the collision rules.. but I don't see how that can help me achieve what I'm trying to do.. As i mentioned before, i don't want it to collide with the caster who summoned the spell but i still want the caster to have collision rules in order to collide with the environment as well as enemy's fireball.

Re: Collision event for fireball

Posted: Thu May 05, 2011 7:24 pm
by Norbo
I used InitialCollisionDetected initially but when the collision of the fireball entity collides with the static mesh, the game crashes. It highlights the error on my space.update(); . Why is that the case?
The ability to remove deferred event creators, like entities, was actually implemented in the development version, which you can grab here: http://bepuphysics.codeplex.com/SourceC ... evelopment

I assume you were using the latest stable release, which did not support it (sorry, I forgot to mention that :)).
Also, i tried playing around with the collision rules.. but I don't see how that can help me achieve what I'm trying to do.. As i mentioned before, i don't want it to collide with the caster who summoned the spell but i still want the caster to have collision rules in order to collide with the environment as well as enemy's fireball.
Collision rules can be used to describe interactions between specific objects and groups of objects, not just a personal state. The CollisionRules object contains Specific, Personal, and Group properties.

-The Specific property allows you to define relationships between specific objects (like a single fireball and its creator). The CollisionRules.AddRule static method offers a shortcut to easily adding pair rules between two objects.
-The Personal property can be used to create objects which behave in the same way with every other object (unless overridden by a Specific rule).
-The Group rule can be used to specify the way groups of objects interact with other objects. Like Player1CharacterGroup, Player1SpellProjectilesGroup, Player2CharacterGroup, Player2SpellProjectilesGroup, etc. You can define Player1CharacterGroup to not collide with Player1SpellProjectilesGroup, and Player2CharacterGroup to not collide with Player2SpellProjectilesGroup, and so on.

The documentation page goes through this in more detail and has a link to a sample.