v 4.2.2
GODOT 4
I am taking the “Brackeys course How to Make a Video Game - Godot Beginner Tutorial.” I am trying to add the roll animation, on my own, since the tutorial never showed how. When I hit the CRTL key the player does not roll. All other animation work but the roll. Can anyone figure out what is happening?
extends CharacterBody2D
const SPEED = 100.0
const JUMP_VELOCITY = -300.0
Get the gravity from the Project Settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting(“physics/2d/default_gravity”) # default value of 980.
@onready var animated_sprite = $AnimatedSprite2D ## references AnimatedSprite2D Node
func _physics_process(delta)
if not is_on_floor():
velocity.y += gravity * delta
# Handle jump.
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = JUMP_VELOCITY
# Flips the sprite
if direction > 0:
animated_sprite.flip_h = false
elif direction < 0:
animated_sprite.flip_h = true
# Play animations
if is_on_floor():
if direction == 0:
animated_sprite.play("Idle")
else:
animated_sprite.play("run")
else:
animated_sprite.play("jump")
**if Input.is_action_just_pressed("Ctl_Button") and is_on_floor():**
** animated_sprite.play(“roll”)**
# Apply movement
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED) # effectively makes the velocity 0
move_and_slide()