Godot Version
4.2.1
Question
Hello Community,
to Time, i learn gdscript and Godot new. In some thing´s i found a own Solution, but now i need some help.
My Code:
extends CharacterBody2D
const SPEED = 300.0
const JUMP_VELOCITY = -400.0
@onready var player = $AnimatedSprite2D
# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
var level_bounds = Rect2(0, 0, 1024, 768) # Beispiel: Spielfeldgröße (anpassen an deine Szene)
func _physics_process(delta):
player.play("Idle")
# Add the gravity.
if not is_on_floor():
velocity.y += gravity * delta
# Handle jump.
if Input.is_action_just_pressed("Jump") and is_on_floor():
if Input.is_action_just_pressed("Left"):
player.play("jump-l")
elif Input.is_action_just_pressed("Right"):
player.play("jump-r")
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("Left", "Right")
if direction:
if direction < 0: # Negative direction means Left
player.play("walk-l")
elif direction > 0: # Positive direction means Right
player.play("walk-r")
velocity.x = direction * SPEED
else:
player.play("Idle")
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()
# Check if player has fallen out of bounds
if position.y > level_bounds.position.y + level_bounds.size.y:
on_player_fallen()
func on_player_fallen():
position.x = 540
position.y = 300
pass
when i go left or right, he give the first image of the Animation walk-l or walk-r, but dont play the full Animation. I have uploaded a Video to show the Problem: https://youtu.be/B4VALgp9QAE