Platformer Springs

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By JayH


I’m looking into making Springs for my platformer, it’s pretty easy so far and it’s all working apart from one thing.

enter image description here

The Spring is made up of:


The problem is that the Player doesn’t always detect his collision after the first bounce. Sometimes he’ll do it once and land on the ground, other times he’ll bounce twice when landing on the Spring. Occasionally he’ll bounce 4 times. Something isn’t in sync.

Here’s part of my script:

	if is_on_floor():
		if not onGround:
			$FootDust.restart() # Reset the Particle effect so that it's not half way though
			$FootDust.emitting = true
			onGround = true
		onGround = false
		if myVelocity.y < 0:
		if myVelocity.y > 0 :
			if playerSpringJump:
				print("Player on Spring!")
				myVelocity.y = -springJumpPower
:bust_in_silhouette: Reply From: Inces

I guess the issue it with is_on_floor function. Your spring collision box must be very close to ground, and sometimes your player assumes is_on_floor is true when already landing.

I’m not exactly sure. My CollisonBox2D isn’t that close, here’s a screenshot:

JayH | 2022-07-26 14:06

show is_on_floor function, show the part where playerSpringJump is set to true, and show the part where velocity.y is forced to 0 upon landing.
You can also print some debug messages inbetween all those 3 places to make sure where is the problem by yourself

Inces | 2022-07-26 17:15

I’ve tested it with Print statements in various locations - it’s the first thing I did, but I don’t know why it is not working each time.

I’m here for some help :wink:

Edit: I have noticed that if I reduce the springJumpPower the Player’s collision works better.

I’m guessing my update isn’t quick enough to catch the Player every time.

enter image description here

JayH | 2022-07-26 17:43

I’ve found a fix, my Gravity was being added to constantly in the fall, so much so the Player was going through the Area2D completely. So I created a Terminal Velocity variable to prevent the Player’s gravity from constantly increasing.


if myVelocity.y > TERMINALVELOCITY:

JayH | 2022-07-26 18:29

my Gravity was being added to constantly in the fall, so much so the
Player was going through the Area2D completely

…and as such triggering is_on_floor too early… :wink:
You are welcome :wink:

Inces | 2022-07-26 20:07