yerzhik Posted May 13, 2014 Share Posted May 13, 2014 My aim is to make a sound effect when a box hits the ground.The problem is that box rotates and moves. Just doing box.intersectsMesh(ground, false); won't help in cases when box is moving and rotating on the ground, because it always will be intersecting the ground and only one sound effect will be made. But every hit of a side of box on the ground should make a new sound. Are there any methods to identify the collision in my case? I have tried to use the:box._boundingInfo.boundingBox.vectorsWorld, I thought its a points of 8 vectors of the box. Then by using them, I am always checking in scene.registerBeforeRender(function () {...}); function, I check each of the 8 points if they intersect with ground object, using intersectsPoint function for ground object.If it intersects, then I push that point into a special array.If next time it happens again, I do not treat it as a new intersection. If it doesn;t intersect, then I remove the point from array.Each time new point is added into array a new collision sound is played. But it didn't work because sound is always played even if box is not moving on the ground,it means that intersection is always happening and then not happening (toggling). Is there any similar project with collision detection? Quote Link to comment Share on other sites More sharing options...
yerzhik Posted May 13, 2014 Author Share Posted May 13, 2014 I have resolved the problem.The issue was not in my code, but in the code of the babylon.js at least here:babylon.boundingBox.js BoundingBox.prototype.intersectsPoint = function (point) { if (this.maximumWorld.x < point.x || this.minimumWorld.x > point.x) return false; if (this.maximumWorld.y < point.y || this.minimumWorld.y > point.y) return false; if (this.maximumWorld.z < point.z || this.minimumWorld.z > point.z) return false; return true; };Its not a good way to do it. I have rewrited the code in the following way (just for my application it works fine): var intersectsPoint = function (point, boundingInfo, delta) {if (boundingInfo.maximumWorld.x - point.x < delta || delta > point.x - boundingInfo.minimumWorld.x)return false;if (boundingInfo.maximumWorld.y - point.y < delta || delta > point.y - boundingInfo.minimumWorld.y)return false;if (boundingInfo.maximumWorld.z - point.z < delta || delta > point.z - boundingInfo.minimumWorld.z)return false;return true;};So I added delta as parameter, and instead of calling:border.intersectsPoint(point);I am calling:intersectsPoint(point, border._boundingInfo.boundingBox, collisionDelta)But I have done it just for boxex, but there are also function for boundingSphere.intersectsPoint Hope that someone will fix the issue with too much sensitive (due to not using delta) intersectsPoint function. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 13, 2014 Share Posted May 13, 2014 Could you elaborate more? I'm interesting in updating these functions with an epsilon value but I would like to be sure to understand why this is better to be less precise Quote Link to comment Share on other sites More sharing options...
yerzhik Posted May 14, 2014 Author Share Posted May 14, 2014 Could you elaborate more? I'm interesting in updating these functions with an epsilon value but I would like to be sure to understand why this is better to be less preciseI had a box moving and rotating on the floor. While moving I was checking if each of the 8 points of the box's corners is intersecting floor or not. If yes, the sound is played and the state of that point is remembered. If its still touching the ground the sound won't be played again, until the state of the point changes again (the point stops touching the ground). When box stops and not moving on the floor, the sound is still played. Because the intersectsPoint is returning true or false randomly. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 15, 2014 Share Posted May 15, 2014 Fixed thanks to you Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.