Hello I am working on my small game project (I am fulltime java developer and playing with Babylon as a HOBBY). I need one very simple thing - I have a Vector3 (bullet moving through space) and I need to detect when it collides with asteroid.
The problem is that Babylon´s intersectsMesh() function return way too much false positives I understand that it uses bounding box (or OBB) inside and THAT is the reason why it returns false positives. But what I dont know is - how to do it otherwise ?
First of all I have to mention, that I am happily playing with meshes, materials, lights and so far I am happy - I DO NOT WANT to dive deep into physics and geometry - thats why I am using library in the first place
Isnt there some oneliner like var collision = myMesh.preciselyCollidesWith(myVector3) somewhere ? I have already found that there are whole physics libraries that shall provide such functionality but it is “whole new world that I dont have capacity to explore” I have looked at some playground examples but they are always like 50 lines of code just to do that. I know that it feels lazy, but thats why libraries were invented in the first place right ?
I know that it could be CPU heavy, I know that I shall only use this precise collision calculation on pre-filtered list of meshes (prefiltered by simpler methods like OBB). Is there something ready to use just as it is ? Or do I really have to implement whole physics system into my project that I will not use for anything else besides just “is this vector inside that mesh ?” thing.
And I have one additional question - I am using particle systems for my explosions and I would be ok with all explosions looking alike. Is there some possibility to save result of particle system in some file / object and then using it repetitively ? I believe that it could save some valuable CPU time when it would not have to calculate partiles again and again.
Thanx sinerely in advance !!! Your library is pretty cool and I know that it is all my fault but as a person that have like 1 - 2 hours / day of time to my “hobby project” I am trying to focus on the game itself by using tools that are available out of the box, rather than dive into every aspect of 3D programming and trying to embrace everything.
Thanx for your reply - I dont know exactly what precision do I need Just as preisely as possible while it steill being playable (FPS wise) I am open to trying several variants.
You have mentioned BoundingSphere, which I would like to try, but function Mesh.intersectsMesh does not have parameter to do that. I can only set TRUE / FALSE (Orientet Box / Axis Oriented Box) but documentation do not mention that it is possible to use BoundingSphere in that function.
I can imagine to use that BSphere as a target for intersection check, instead of the mesh itself.
**shotMesh.intersects(asteroidMesh.getBoundingInfo().boundingSphere) ** you meant something like that ? I could definitely give it a try.
I can also scale that bounding sphere down for like 5% if it creates better real-world results ? False negatives are more acceptable than false positives in my case.
Hello, I am not exactly sure what do you mean by “raycast” - I mean I know about that technique, but I am not sure about its correct implementation.
What I am doing at this moment is:
I have one mesh that is very long and thin tube
When I shot, I rotate this tube to the direction of that shot
I cycle through all my asteroids and check, if that tube intersectsWith them and save intersected ones with distance information into an array. I am using bounding spheres as they work better than boxes in my case.
When shot passes appropriate distance, I double-check intersection with mesh that I have found in step 3 and if everything goes well, considering as being hit.
What exactly do you mean by Raycasting ? I think that my rotated tube actually doing the same, isnt it ? With actual results I am ok, bounding spheres are precise enough for my use case. But offcoures I would try something even better if possible, but as I said, I would be happier with just Babylon.js as I am afraid that implement whole new library would be quite complicated ?
This process sounds just very heavy and complicated. I imagine the first mesh that is hit by the bullet will take the hit? Unless your bullet can go through some materials, changing its range, velocity and the damage taken (which would make it a bit more complex).
I believe what @Cedric means with using rays is that when you aim and shoot your bullet from a distance, the ray cast from the source in the direction of aiming catches the first mesh that will be hit by the bullet. When the bullet reaches this point (hit), it is detected and makes for the impact (animation) and damage taken (game state). That’s it, that’s all. Else, You could also have a look at yuka
Here’s a link for an FPS demo: https://yuka.babylonjs.xyz/js/playground/hideAndSeek/