# Object falls through the floor because of high velocity

## Recommended Posts

I'm not sure if it's exactly Babylon.js question, but here's the situation I can't deal with for a while now...

I have a box (player), that has velocity and etc. things, right? While the box doesn't touch (intersects) anything it's — player.velocityY -= worldGravity, when it touches something — player.velocityY = 0 and no worldGravity applies anymore, right? Things work as they should. The problem is that -velocityY is so high that player gets inside of the floor and only then stops.

I tried everything I could: intersects for meshes, for bounding boxes, points, even rays infos (distance and etc.); but nothing helps because -velocityY is higher than collision code runs (I'm not sure but that's my only though, since less velocity works just fine). Player's velocity by Y gets between -8 and 0, while gravity is 0.25.

Any thoughts?

player.y++ while intersects isn't an option, of course.

##### Share on other sites

I didn't really understand everything but it seems your expression is not homogenous. velocityY I guess is m/s (meter per second) whereas worldGravity is m/s2 (meter per square second) so to set your velocity you need to multiply by the delta time.

##### Share on other sites

This is a problem faced by all collisions/physics engine. I'm afraid that the only efficient way is to subdivide your simulation into smaller steps

##### Share on other sites

I didn't really understand everything but it seems your expression is not homogenous. velocityY I guess is m/s (meter per second) whereas worldGravity is m/s2 (meter per square second) so to set your velocity you need to multiply by the delta time.

Thanks for the tip, but I tried it as well before, results are all the same

This is a problem faced by all collisions/physics engine. I'm afraid that the only efficient way is to subdivide your simulation into smaller steps

That's the thing I was afraid of, but I hoped there is some solution anyway. Thank you for the answer

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

I did a thing though. I return += gravity to the object (twice) when it touches the ground (or whatever). It's a bit wrong and some tricky way to do it, but at least it works for now (until I'll find some more proper solution, of course). The only problem I have because of that are some little jumps back.

I hope to get some more things done before I'll show my thing to the forums (pretty much my very first html, css, 3D and javascript experience ever). I tried three.js, physi.js and cannon.js before I found babylon.js and I really love how things done here

Later!

##### Share on other sites

There is a way and it's called ray tracing for collision. http://www.gamedev.net/topic/350988-raytracing-for-collision-detection/

You simply take the projection calculate how much time it needs to hit something than check if that much time has passed then if it has..assume it has hit the target.

However this is only done for very fast things. Because slower things may change direction as user interact with them (they are dynamic)....but if you were to check then the most common way to solve this is to check for negative position compared to all places...cpu expensive but the only way so far, at least to me.  If let say ground is at 0 and your ball objects checks its position to be -2 then make it 0 and then tell rest of the program to continue as it would normally.

##### Share on other sites

There is a way and it's called ray tracing for collision. http://www.gamedev.net/topic/350988-raytracing-for-collision-detection/

You simply take the projection calculate how much time it needs to hit something than check if that much time has passed then if it has..assume it has hit the target.

However this is only done for very fast things. Because slower things may change direction as user interact with them (they are dynamic)....but if you were to check then the most common way to solve this is to check for negative position compared to all places...cpu expensive but the only way so far, at least to me.  If let say ground is at 0 and your ball objects checks its position to be -2 then make it 0 and then tell rest of the program to continue as it would normally.

Thank you for the tip. As I said before, I tried rays, but it looks like it ended up in the wrong way. I'll try one more time.

UPDATE: I just figured out it was different ray thing, sorry

##### Share on other sites

So, I've made some progress because of using 'minimum' and 'maximumWorld' of bounding boxes and checking object's bottom, instead of just subtracting and adding stuff, but still not happy with result. There's still one frame where I can see it gets into anything sometimes, because '-y' step is still more than distance between falling object and ground. Whatever I do — I keep running in circles, in result; that's just a lack of experience in programming, I believe. Well, at least one more week (I hope) of headaches and I'll figure it out

I've read things about ray tracing collisions, but I don't know how to make some things for it, hopefully I'll figure out these things too.

It's hard to be noob

## 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.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.