Godot Version
v4.4.1.stable.official [49a5bc7b6]
Question
Hi there!
I am working on a small auto jumper game and bumped into some problems that I can’t seem to fix or find an answer for.
The game works like your standard auto/endless jumper where the player jumps up platforms to get as high as possible. As it is an auto jumper the player is jumping constantly. Most platforms are set up with one way collision so the player can jump through them from below and bounce off from above.
The problems I am having is which some of the ‘special’ platforms (bouncy, breakable, etc.). These are set up in the same way to a normal platform with a AnimatableBody2D with a CollisionShape2D (one way collision) and a Sprite2D, but also feature a Area2D with its own CollisionShape2D (see image for collision shapes) in order to detect whether the player is colliding with the the special platform (from above).
Then, in the script attached to the AnimatableBody2D for the bouncy platform I do the following:
extends AnimatableBody2D
@export var bounce_strength: float = -500.0 # adjust for higher/lower bounce
func _on_area_2d_body_entered(body: Node2D) -> void:
if body.is_in_group("player") and body.global_position.y < global_position.y:
body.velocity.y = bounce_strength
As you can see, I do a simple check when the signal is emitted from the Area2D node that the player has entered and that the player is coming from above the platform (as I do not want to trigger the bounce when the player is jumping up through the platform).
This seems to work about 80% of the time, but the remaining 20% the bounce will not trigger. I am having a hard time figuring out what is happening as there does not seem to be any consistent method of replicating the bug. It will happen even if there is no difference between the jumps, so it might trigger once, but not trigger the next time even if the player bounces on the platform without changing direction or giving any input.
My guess is that it has something to do with the function for the player movement (auto jumping as soon as the player is on the floor) being triggered before the function in the platform code is executed. But my knowledge is too limited to confirm or even investigate this.
I would really appreciate any help!
