Inaccurate RayHelper for Jumping Character

Hello, BabylonJS friends! :slight_smile:

I’ve been tinkering around with rays a bit and, in this PG example, I can’t seem to figure why the character mesh falls partially through the floor when landing after a jump. I turned on the RayHelper visual to see it, and noticed that it doesn’t accurately follow the character mesh as it moves up and down. Is there a way to have it be more stable so as to avoid the character missing the floor and sticking through it?

Hope you can help – thanks! :smiley:

You could either rely on the built in collision system: https://playground.babylonjs.com/#UP84Y8#15

But let s check your current case :slight_smile:

Your ray is attach to a mesh your moving. Unfortunately, you are testing “one frame behind”. Basically you pick from the current ray position, then move the mesh so the mesh is in front of the ray and the faster the mesh goes the more it will be in front of the ray. You can actually see here the impact:

https://playground.babylonjs.com/#UP84Y8#21

So in your case you could either cast a ray to where your mesh would be so it would never appear after the ray. Basically you need to compute the ray yourself instead of relying on the helper and you could move the player manually.

3 Likes

I appreciate your response, @sebavan!

I’m afraid I don’t know what I’m looking for in the first link you posted, would you mind elaborating on that a bit?

As for the ray being one frame behind, that makes a lot of sense; it does behave that way when watched closely. If I were to cast the ray where the mesh is going to be, do you happen to know how I might go about it? I’ve seen a few examples reference .computeWorldMatrix(), though I’m at a loss as to how to implement it (pretty new to BabylonJS) :smiley:

This is one example I’ve seen that seems to keep the ray following correctly. I think maybe I’m just not understanding how it’s working. :open_mouth:

Ohhhhh the first example is totally the wrong link :slight_smile: the idea was to enable collision in babylon: https://playground.babylonjs.com/#UP84Y8#22

And in your link it works cause the move is done before the picking which is not the case in your code. you conditionally move after pick.

2 Likes

Ah fantastic! This will be perfect for what I’m looking to do. Thank you once again, @sebavan – you rock :smiley: