Implementing collision alerts

Ok, I feel like there has to be a better way of implementing this, as my way is requiring me to add hacks to my game that weren't needed until now and probably wouldn't be beyond this.



I'm trying to implement a collision alert system. Basically, if one of my fast-moving asteroids is going to collide with the player then an alert should sound.



Initially I thought of using a ray for this, but realized that it wouldn't trigger on collisions that weren't dead on, because the edge of an asteroid could clip the player and never intersect the ray. Then I thought of attaching a cylinder to the front of each asteroid, ensuring that the cylinder is always oriented in the direction of motion and triggering the alert whenever this cylinder geometry collides with the player, dynamically setting its height to a factor of the speed–speed*3 for 3 seconds of warning, for instance.



This sorta works, but it seems very ugly. For starters, I'm using two different types of collisions. I'm using JMEPhysics to model physical collisions, bouncing, etc. I'm also using BoundingCollisionResults in one place–I have a willCollide() method on my Entity class that reports whether or not an entity will collide if activated at its current position, such that the game can ensure that it isn't randomly positioning targets inside each other without performing a collision check that doesn't tamper with the simulation physically.



But where this solution seems to get ugly is that I don't have a way of distinguishing between physical and non-physical geometries–that is, the spheres and boxes representing the asteroid shell and ship hull are physical, while the collider cylinders on the tips of the asteroids are not. There's a bounding box around everything, but my willCollide() method doesn't know that the cylinders don't need to be checked. And I could hack in a distinction such that there's a getGeometry() method on my Entity class, but it just doesn't seem like I'm on the right track with this. :slight_smile:



So, is there a better way? Could I perhaps do something with the local coordinate spaces? I was reading the AI tutorial on the wiki which mentioned that an object's local coordinate space could be used to determine whether another object was behind it, but how does one go about translating some other object higher up on the scene graph into another's local coordinate space? And would it then work as I'm thinking it would (I.e. an object at {0, 0, -2} would be two units ahead if these coordinates were local, regardless of which direction the object in whose local coordinate space these coords are is facing?



Thanks.

I would suggest putting your "early warning cylinder detection system" geometry into a separate branch in the scene graph and check the collisions with jME. The physics do not need to about these cylinders, so you shouldn't need to add them to the physics system. That way you don't have to hack your physics stuff to check this, it can be completely separate. Say, add a node named warningNode to the root node in your game state or wherever, and add all you cylinders to this. Whenever your asteroids move update the cylinder for it. When ever you want to check for a warning, do a ship.getCollision(warningNode, collisionResults) and that should do the trick.



Does this help at all, or am I running the wrong way?