Godot Version
4.2.2
Question
What is a good way to handle phasing through colliders when jumping in a 2D platformer?
Context
I’m fairly new to Godot. I’ve been running into an issue that has been driving me nuts. It’s probably something simple that I’m not getting.
I’m making a 2D platformer and I’m trying to write some code that will re-enable a collider when I phase through a platform. I’m using a hitbox collider for detection and a feet collider to handle the actual physics of landing on a platform.
Outside of the excerpt I share below, my code has logic that involves applying a force to the player and disabling the “_feet_collider” variable upon applying this force
Here is my code:
func _ready():
_hitbox.body_exited.connect(_exit_feet_collider)
_hitbox.body_entered.connect(_entered_feet_collider)
pass
Code below doesn’t work for some reason
func _exit_feet_collider(body):
if body.collision_layer == 1 and _feet_collider.disabled:
if jumping:
print(“feet collider enabled”)
_feet_collider.disabled = false
func _entered_feet_collider(body):
if body.collision_layer == 1 and _feet_collider.disabled:
print(“collider is disabled!”)
###########################
The odd part is that I’m using the collider debug mode to visualize when the _feet_collider is disabled or not, and when I run the game I can see that the feet collider is enabled when it is needed, yet the player still phases through the platform.
Any alternative suggestions or advice would be greatly appreciated. Thank you!