@ndebruyn said:
My biggest obstacle with this approach is, what will be the fastest way to check collision between different electrons, not just the player.
I could do the distance check but then I will have to loop through all electrons on each game loop to see if a collision occured, well actually more than just one loop.
It will be a loop for each electron on each game loop update. And that is BAD.
I could make use of the Rays in jME and shoot 4 different rays from the center of each electron and check for collisions in that way.
that might be a better approach.
Also, I have to concept of obstacles in the game. These obstacles are more than just spheres, how would I do that then with distance,
Any suggestions or help would be highly appreciated.
What would you be shooting the rays against? I canât see how it would be anything other than âall of the other electronsâ. A ray check is WAY more expensive than a non-sqrtâed distance check.
Here is the pseudo code to check all objects against one another in the brute force way. Bonus points if you put them in an array.
[java]
Spatial someObjects
float thresholdSquared = âŚ
for( int i = 0; i < someObjects.length; i++ ) {
Spatial s1 = someObjects[i];
Vector3f loc1 = s1.getWorldTranslation();
for( int j = i + 1; j < someObjects.length; j++ ) {
Spatial s2 = someObjects[j];
float distSq = s2.getWorldTranslation().distanceSquared(loc1);
if( distSq < threshold ) {
// These two spatials collide
}
}
}
[/java]
There is no magic⌠something is going to be doing a loop like that somewhere. Whether itâs inside bullet or whether you are hiding it in a collideWith(Ray) [which is actually much much worse even]. It might as well be as fast and efficient as possible⌠and really, that one will take a fraction of the time of all of the loops JME is already doing every frame.
Edit: sphere to bounding box (assuming the obstacles are bounding boxes or something) is not much harder than the above. Essentially, two dot products instead of a direct distance check.
How many electrons do you have? What happens when they hit each other versus the player? How many obstacles will you have?
The bottom line, for what appears to be a pretty low number of objects, Bullet is probably not doing anything magic for you.