Help With Body Contact Behavior
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Help With Body Contact Behavior
I don't really understand how this is working, but I noticed that I can jump before I hit the ground. How I'm detecting the ground is a sensor fixture that tests for the user data in the floor. If you press "p", you can see the hitboxes. The small box (the sensor) below the player (the purple square) isn't coming into contact with the ground before the player jumps again. I would think that the frame the sensor is coming into contact with the floor isn't being rendered, but I don't really know that much about how this works so if anyone can tell me whats happening or how to fix it it would be greatly appreciated!
- Attachments
-
- playercontroller.love
- (3.93 KiB) Downloaded 127 times
gaeem defelpmint is maiy pashin
Itch: Freakman
Itch: Freakman
Re: Help With Body Contact Behavior
Your isGrounded check is incorrect. First off, you need to check for contact:isTouching() and it helps to check the collision normal too. The collision normal will show you if the player is actually being pushed "up":
https://2dengine.com/?p=box2d#Is_the_bo ... ng_an_axis?
https://2dengine.com/?p=box2d#Is_the_bo ... ng_an_axis?
Re: Help With Body Contact Behavior
I think what is happening, apart from what ivan is saying, is that without vsync, it's very unlikely that the frame where the player is touching the ground is shown at all, because it only happens during a very short instant.
I tried enabling vsync and it made the player be shown touching the ground.
Edit: An alternative if you absolutely want to keep vsync off, is to disable jumping when the player touches the ground, and re-enable it with a timer that lasts for the duration of a typical frame, say 1/60 or so.
I tried enabling vsync and it made the player be shown touching the ground.
Edit: An alternative if you absolutely want to keep vsync off, is to disable jumping when the player touches the ground, and re-enable it with a timer that lasts for the duration of a typical frame, say 1/60 or so.
Re: Help With Body Contact Behavior
Thanks for the help. I ended up going with bump.lua mainly because the wiki kept telling me to, and I'm not exactly making a physics simulator. I found it to be a lot more intuitive and easy to understand. What I ended up going with was the collision normal, which in bump.lua looks like this:
This also made the "air hopping" less apparent and it's at a point that I can live with it.
Code: Select all
-- len being the length of cols (the collisions)
for i=1,len do
local other = cols[i].other
pc.grounded = (other.isGround and cols[i].normal.x == 0 and cols[i].normal.y == -1)
end
if len == 0 then
pc.grounded = false
end
gaeem defelpmint is maiy pashin
Itch: Freakman
Itch: Freakman
Re: Help With Body Contact Behavior
Box2D is a very powerful library, although its API can be a little overwhelming.
Also, note that you should be especially careful with checks like x == 0 or y == -1.
With floating point numbers (like collision normals) this check won't work as expected.
Plus, the player could be standing on a slope in which case "y" won't be -1.
Also, note that you should be especially careful with checks like x == 0 or y == -1.
With floating point numbers (like collision normals) this check won't work as expected.
Plus, the player could be standing on a slope in which case "y" won't be -1.
Re: Help With Body Contact Behavior
More specifically, floating point numbers have limited number of decimal places to work with, so pretty much every math operation is guaranteed to produce tiny errors in the last digit, so a floating point number is never exactly equal to any specific value unless you set it to that specific value. One notable exception is that double-precision floating point numbers (the ones used in Lua) can store integers exactly, and integer-producing operations will never result in slightly-off-integer value. Double floats are 64 bits wide but you only have 53 bits of integer space to work with.
Re: Help With Body Contact Behavior
I don't think bump will return anything other than 0, 1 or -1.
https://github.com/kikito/bump.lua/blob ... mp.lua#L90
https://github.com/kikito/bump.lua/blob ... p.lua#L178
https://github.com/kikito/bump.lua/blob ... mp.lua#L90
https://github.com/kikito/bump.lua/blob ... p.lua#L178
Re: Help With Body Contact Behavior
Good catch there. Still I don't recommend == for non integers.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 1 guest