Error: godot is_on_wall not working

What's Causing This Error

The is_on_wall() function in Godot is used to determine if a KinematicBody2D or KinematicBody is in contact with a wall. If this function isn't working as expected, it could be due to several reasons:

  • The physics engine may not register the collision because the body is not moving towards the wall with enough velocity.
  • There could be an issue with the collision layers and masks setup, where the layers that represent walls are not set to interact with the layer on which the player resides.
  • The is_on_wall() method will only return true during the physics process after move_and_slide() has been called, so it must be checked in the correct context.
  • Improper use of move_and_slide() can also lead to unexpected results. For instance, not using or incorrectly setting the up_direction parameter can affect how the engine interprets collisions with walls.
  • Collision shapes might be improperly configured or absent. This would prevent the physics engine from detecting any collisions at all.

Solution - Here's How To Resolve It

To resolve issues with is_on_wall() not working correctly, consider the following solutions:

  • Ensure that you're calling is_on_wall() after the move_and_slide() method in the _physics_process() function.
  • Review your collision layers and masks to make sure that the player and the wall are set to interact with each other. You can adjust these settings in the "Collision" tab of the relevant nodes.
  • If you've overridden _process(delta) instead of _physics_process(delta), switch to _physics_process(delta) for physics-related checks to ensure they're done in sync with the physics engine.
  • When using move_and_slide(), make sure that the up_direction vector is set correctly if your game relies on gravity (for example, Vector2.UP in a 2D game).
  • Double-check the collision shapes of your characters and walls. They need to be properly sized, positioned, and parented to the correct nodes.
  • As a debugging step, use the debug property to visualize the collision shapes when the game is running.
  • Make sure the KinematicBody (2D or 3D) has a non-zero velocity towards the wall when checking for is_on_wall(). If the character isn't moving, the method won't register a collision.

By troubleshooting each of these areas, you should be able to identify the cause of the is_on_wall() function not working and rectify it accordingly.

Was this content helpful?

Start building today

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.