Godot Version
4.6.2
Question
I look around the internet for how people tend to approach a climbing mechanic, in this case, my objective is to be able to stick to a wall and slide up and down using raycasts to detect if the surface is climbable. I currently have some code as a result of trying to figure it out, but does not work properly.
A.) going against the surface the raycasts are supposed to detect doesn’t do much. I did this by setting the raycasts and the ladder to the same collision layer. The rays will turn red to indicate colliding, however when I go against the ladder, they do not seem to work the same. B.) I just don’t know if I’m doing the math right. I decided to try and add onto the y velocity of the player, I’m unsure how to have the transform be unaffected by gravity though, as when the rays are colliding I don’t want to be able to fall back down.
I hope this was clear enough. This is my script that handles climbing though:
class_name Climbing extends Node
@onready var player: CharacterBody3D = get_parent()
@onready var climb_ray: RayCast3D = %ClimbRay
@onready var climb_stop_ray: RayCast3D = %ClimbStopRay
var climbing := false
var climb_speed := 10
@onready var movement_component: MovementComponent = %MovementComponent
func _climbing(delta: float) -> void:
print(climbing)
if climb_ray.is_colliding() and climb_stop_ray.is_colliding():
climbing = true
else:
climbing = false
if climbing == true:
player.velocity.y += movement_component.direction.y * climb_speed * delta
player.move_and_slide()