Player Falls too Fast to be Detected by Area2D

Godot Version

Godot 4.2.1

Question

I am making a platformer and am currently making a bounce pad thing. This bounce pad converts the players downwards velocity into vertical velocity if they are falling fast enough, and if they aren’t it gives them a set amount of vertical velocity. The issue is that it occasionally gives them the set amount of vertical velocity when it should convert their falling velocity into vertical velocity, resulting in a much shorter bounce. I believe the problem is that the player falls too fast and hits the ground before the Area2D that the bounce pad is made of detects them. Is there any way to make that not happen?

Here is the code in case that is relevant:
func _on_body_entered(body):
if body is Player:
if body.velocity.y > 400:
body.velocity.y = -body.velocity.y
else:
body.velocity.y = -400

the player is characterbody2d? then can use the move_and_collide and get the KinematicCollision2D. if it’s a bounce pad then add velocity

Does entering an area2D count as a collision? Yes the player is a characterbody2D, but the bounce pad itself is an area2D.

the bouncepad has collisionShape2d?. then it will detect the area2d based on the collisionShape2d’s shape

I want to use move_and_slide() for the sliding functionality, but move_and_slide() doesn’t detect the area2d as a collision.

the area2d has a collisionShape2d as a child?
mind show your area2d?

it does have a collisionshape2d

I have also tried making the collisionshape2D larger to fix the issue, but that’s only partially effective

so you are saying that if you make the jumper larger, it can detect it?

if the player falls from too high up, it does not detect it.

did you try to get the collision by get_slide_collision see if the characterbody actually collided with anything

I just double checked it, and it does indeed collide with the ground

when it works as intended it detects no collision

well um maybe then you should extend the collisionshape to be larger below the ground so it can detect it

Both moving the area2d into the ground and slightly above the ground don’t work sadly. Thanks for the help anyway though.

what happen if you slowdown the player movement/fall, it should be able to detect it then?

While that would work, I like the way the movement is currently. I just decided to make the bounce pad large enough to where the problem doesn’t really matter anymore. While it is larger than I would prefer it to be, it’s nothing too terrible.

This is a very common problem (in any engine). You guessed it right about the reason - the player is moving too fast. Although usually it happens with bullets.

What happens is at one frame the player is above your area2d, then it moves a great distance because the velocity is very large, and on the next frame the player is already below your area2d. So there is no frame where the player and the area would properly intersect.

Surely it can be solved by making colliders thicker or decreasing velocity of moving objects, but usually it is solved by using a raycast. You shoot a raycast from the player position in a direction it’s moving for the length of the velocity vector. And every frame you check if this raycast collides with your area2D. If it does, you can either “bounce” player right away (at this speed it won’t be very noticeable that the player bounced before actually touching the area), or at this frame instead of using your normal movement logic teleport the player into the area so it can do the bounce for you at the next frame.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.