kurhlaa Posted December 10, 2017 Share Posted December 10, 2017 Hello, Some people offer to use BABYLON.ActionManager.OnIntersectionEnterTrigger and BABYLON.ActionManager.OnIntersectionExitTrigger to detect when one mesh collides with the other. I like the idea because an event is triggered only once. However, when I try - https://www.babylonjs-playground.com/#7NQA2K - moving with A and D, nothing happens when red box collides with a blue box. Am I missing something or OnIntersectionEnterTrigger is being triggered only when one object is actually inside the other (I tried disabling collisions)? I really don't wan't to use box.onCollide = function(collidedMesh) { because it's being executed in a loop forever in a FPS-like game - even when there are no other meshes near you - onCollide() will still happen because collidedMesh is a ground. It would be great to have a BABYLON.ActionManager.OnCollisionEnterTrigger and BABYLON.ActionManager.OnCollisionExitTrigger functions, which run only once, if it's impossible to get such functionality at the moment. Quote Link to comment Share on other sites More sharing options...
JohnK Posted December 11, 2017 Share Posted December 11, 2017 Have a play with this https://www.babylonjs-playground.com/#7NQA2K#1 Quote Link to comment Share on other sites More sharing options...
kurhlaa Posted December 11, 2017 Author Share Posted December 11, 2017 @JohnK, thanks, but that breaks all default collisions with all other objects I need them. But I've just got a great idea - I can make around my character the most basic box, make it a little bigger than character, fully transparent, red box will be it's parent - and check for ersectionEnterTrigger between it and blue box! This will allow to save built-in collisions and add triggers for collisions with needed objects. Moreover it will be transparent - should be cheap calculations for WebGL. What do you think? Quote Link to comment Share on other sites More sharing options...
kurhlaa Posted December 11, 2017 Author Share Posted December 11, 2017 BABYLON.ActionManager.OnCollisionEnterTrigger still would be much better. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted December 11, 2017 Share Posted December 11, 2017 Hello, There is no intersection actually thanks to the collision engine so there is no problem per se You have to rely on onCollide and just make sure that your code is executed only for the meshes you want Quote Link to comment Share on other sites More sharing options...
kurhlaa Posted December 11, 2017 Author Share Posted December 11, 2017 @Deltakosh, that makes a JavaScript code (getting an object, getting his name/id, comparing to the needed string, etc) execution in a loop forever I find it bad for performance and CPU load. Is it technically possible efficiently to implement BABYLON.ActionManager.OnCollisionEnterTrigger ? Like for intersections, but for collisions. If yes - avoiding onCollide for such tasks would greatly improve performance Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted December 11, 2017 Share Posted December 11, 2017 Unfortunately I wills till have to rely on onCollide internally. This is the same issue: being noticed that a collision happened and then find between whom Quote Link to comment Share on other sites More sharing options...
JohnK Posted December 11, 2017 Share Posted December 11, 2017 Is this still the allowJump problem. If I understand you correctly you only want a jump action possible if the "character" or "camera as character" is in contact with an object, for example the ground. So you want If character in collision allowJump = true If character exits collision allowJump = false Quote Link to comment Share on other sites More sharing options...
kurhlaa Posted December 11, 2017 Author Share Posted December 11, 2017 @Deltakosh, internally is there a function like onIntersect which runs forever in a loop to check for intersections? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted December 11, 2017 Share Posted December 11, 2017 yes https://github.com/BabylonJS/Babylon.js/blob/master/src/babylon.scene.ts#L3307 Quote Link to comment Share on other sites More sharing options...
kurhlaa Posted December 11, 2017 Author Share Posted December 11, 2017 @JohnK, no, but you gave me another great idea with jumping also I could use my idea with transparent child to detect whether I'm on a ground - allow jumping only if it intersects the ground. So just 1 trigger - no more infinite loops. But in this case I'm thinking about an efficient way to walk upstairs. If I collide with a stair - move me UP and FORWARD a little. And again - no more infinite loops, just simple trigger, which runs once after collision with stairs. But as always - sounds good.. but need to try to realize it 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.