I'm using the character 2d body with a player template. I attached area 2d to the player node and I want to make a bool value that will turn off gravity when the area touches a wall so the player can double jump. When the area stops making contact, gravity will be re-applied. Does anyone know a way I could do this? I'll share code of my attempts below.
#Boolean Area2d?
1 messages · Page 1 of 1 (latest)
extends CharacterBody2D
const SPEED = 300.0
const JUMP_VELOCITY = -400.0
func _on_climb_hitbox_area_entered(_area: Area2D) -> void:
var _climb := true
func _on_climb_hitbox_area_exited(_area: Area2D) -> void:
var _climb := false
func _physics_process(delta: float) -> void:
# Add the gravity.
if not is_on_floor() or _climb == true:
velocity += get_gravity() * delta
# Handle jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var direction := Input.get_axis("ui_left", "ui_right")
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()
The issue is probably something simple but I'm REALLY new so any explanation would be welcome
What exactly is the behavior you are trying to achieve? Jumping off the wall? Sticking to the wall? In either case, you probably should use raycasts