Godot Version
4.6
Question
I have this problem where the player (represented by a capsule) is standing against the wall
and when I jump and I’m in the air, is_on_wall() is not returning true
UNLESS I’m actively pressing forward against the wall.
The moment I let go of forward (and I’m still in the air), is_on_wall() returns false. I would like to detect that I’m on the wall without having me to actively press forward against it (while I’m in the air). How would I go about doing this?
Remember, the capsule is right up against the wall this entire time.
Here’s my code:
Everything is in physics_process and very little was added to the CharacterBody3D: Basic Movement script
func _physics_process(delta: float) -> void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
# handle jump
if Input.is_action_just_pressed("ui_accept") && currentState == State.Floor:
velocity.y = JUMP_VELOCITY
# handle input direction
var input_dir := Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
var direction := (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if direction:
velocity.x = direction.x * WALK_SPEED
velocity.z = direction.z * WALK_SPEED
else:
velocity.x = move_toward(velocity.x, 0, WALK_SPEED)
velocity.z = move_toward(velocity.z, 0, WALK_SPEED)
# handle state
if is_on_wall_only():
currentState = State.Wall
elif is_on_floor():
currentState = State.Floor
else:
currentState = State.Air
state_signal.emit(currentState)
move_and_slide()
Edit: So I marked one of the comments as the solution but if anyone knows how to solve this without any additional runtime checks (raycast, shapecast, etc), please let us know, because ideally, I would like is_on_wall_only() to just work (using Jolt) without having to do any extra stuff. Regarding the raycast suggestion, it’s definitely less expensive to detect the collision (compared to shapecast) and is perfect if you’re only concerned about one direction (i.e. in front of you, etc), but for me, shapecast fits my needs because it can detect the wall from all directions with the tradeoff that it’s more expensive to compute compared to a ray.






