Jump to content

Detecting if mesh is not colliding with anything


Recommended Posts

I'm trying to implement double jump (one extra jump while in the air). In order for it to work also when the character is falling of a ledge or higher platform without having initiated a jump from the ground I need a way to tell if the player is currently in the air or not. How can i tell if a mesh is currently not colliding with anything? 

The only way I have found so far is the "intersectsMesh(mesh,precise)" function, but this requires me to check against a specific mesh. Would I need to loop through all meshes with collision in the scene to check if I am currently colliding with any of them, is there any better way to do this (seems rather inefficient). What I think I'm looking for is a "isCurrentlyColliding" value on my character mesh or perhaps it can be solved differently?


Link to comment
Share on other sites

I have questions about how do you generally know where the character is and what it is doing. I am imagining a a group of non connected platforms at different positions left to right and front to back at different heights. But lets simplify to just platforms left and right at the same height will ground  below. The character is on a platform and can

1. Jump onto another platform, how do you know which platform it lands on?

2. The character falls of a platform. How do you know which one it fell off?

3. The character runs along the ground and jumps onto a platform. How do you know which platform it jumps on?

You could do all this by checking for all platforms which intersects with the character. 

For me some sort of mapping system for character and platforms would work better. 

Answering my questions may lead you to an answer for yours.

Link to comment
Share on other sites

To all 3 of those points the answer is basically "I don't". However, I believe I have come up with a workaround to it. If I create a velocity vector based on the previous and current position I can see if there is any vertical movement. This is only part one as the character could be moving up or down on a sloped platform and still be considered grounded. If there is any vertical movement, set a variable name "potentiallyInTheAir" to true. Using the onCollide callback for the mesh, if the callback triggers (assumingly it will each frame if there is any collision) the potentiallyInTheAir is flipped back to false. On the next frame i can check the potentiallyInTheAir variable and handle the jumping logic appropriately. If there is vertical movement and I did not receive an onCollide callback in the last frame, I can assume that I am in the air. I have not actually been able to test this yet, so its more of a pseudo algorithm in my head.

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.

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.


  • Recently Browsing   0 members

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