Is_on_wall() not performed under the velocity.y

Godot Version

4.3 Stable

Question

extends  NodeState
@onready var character_body_2d: CharacterBody2D = $"../.."
@onready var animated_sprite_2d: AnimatedSprite2D = $"../../AnimatedSprite2D"

const SPEED: int = 1

var parent_node

func _ready() -> void:
	parent_node = get_parent()

func on_process(_delta : float):
	pass
	
func on_physics_process(_delta : float):
	
	character_body_2d.velocity.x = 0
	
	if GameInputEvents.up_input():
		character_body_2d.velocity.y = -100
		animated_sprite_2d.play("climbing")
	elif GameInputEvents.crouch_input():
		character_body_2d.velocity.y = 100
		animated_sprite_2d.play_backwards("climbing")
	else:
		character_body_2d.velocity.y = 0 
		animated_sprite_2d.play("start_climbing")
	
	if character_body_2d.is_on_wall():
		print("is on wall")
	else:
		print("is out wall")
		
	character_body_2d.move_and_slide()
func enter():
	animated_sprite_2d.play("start_climbing")
	#LevelManager.autoload_climbing = true
	
func exit():
	animated_sprite_2d.stop()
	
	
	

If velocity.y moving because I press the input event, the character_body_2d.is_on_wall() became false

this obstacle for me, because I can’t manipulate character_body_2d movement. because currently my “Player” when in this state(“climbing”) can move up and down even he not in the wall (tile map) anymore.

Chat GPT can’t solve this situation, and she tell me it’s because the movement too fast and is_on_wall() failed

To have a bigger range and guarantee to detect a collision with a wall you can use an area3D as child of the characterBody3D (set it’s collision shape to a box shape and make it slightly bigger than the characterBody3D’s collision shape and position it so it sticks out only on the left and right sight of the player ) and just check if it has any overlapping bodies via

has_overlapping_bodies()

“Thanks for responding to my question. I added an Area2D and Collision2D to detect my ‘Player.’ is_on_wall() isn’t reliable in my case. Thanks again!”