Hey everyone š
Iām working on a simple platformer in Godot 4 and running into a weird issue:
My player starts floating slightly above the ground.
Jumping works strangely .
Iām using CharacterBody2D with move_and_slide() and gravity.
here's my charcter script :
extends CharacterBody2D
@onready var sprite = $AnimatedSprite2D
var speed = 150
var jump_force = -500
var gravity = 1200 # Stronger gravity = no floating
func _physics_process(delta):
# Apply gravity pulling down
velocity.y += gravity * delta
var on_ground = is_on_floor()
# Right movement
if Input.is_action_pressed("right"):
velocity.x = speed
if on_ground:
sprite.play("run")
else:
velocity.x = 0
if on_ground:
sprite.play("idle")
# Jumping
if Input.is_action_just_pressed("space") and on_ground:
velocity.y = jump_force
sprite.play("jump")
# Stay in jump animation while airborne
if not on_ground:
sprite.play("jump")
# Apply movement
move_and_slide()
if is_on_floor():
print("Standing on ground at X:", position.x)
else:
print("In air at X:", position.x)
its so simple it shouldnt cause any issue.
any help would be appreciated
thanks
