Godot Version
4.6.1
Question
Hi there - my glide code for my pigeon isnt working - any ideas why? gravity just isnt changing at all
extends CharacterBody2D
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
const SPEED = 150.0
const JUMP_VELOCITY = -200.0
var glide_gravity_multiplier = 0.2 #Reduce gravity to 20% while gliding
func _physics_process(delta: float) -> void:
var current_gravity = gravity
if Input.is_action_pressed("glide") and not is_on_floor():
current_gravity = glide_gravity_multiplier * gravity
velocity.y = min(velocity.y, 100)
if not is_on_floor():
velocity.y += current_gravity * delta
# Handle jump.
if Input.is_action_just_pressed("Jump") 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()