Jump to content

OnIntersectionEnterTrigger from collision detection


kurhlaa
 Share

Recommended Posts

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.

Link to comment
Share on other sites

@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?

Link to comment
Share on other sites

@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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

@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

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...