Hi! I've recently switched from visual scripting in Unreal Engine to Godot, so I'm very much getting to grips with GDScript. I'm making a sidescrolling platformer and I'm having trouble switching my character animation back to running, after the jump animation is triggered.
I'm using Dialogue Manager, and had a lot of trouble disabling player movement. This mostly seems to work, but when the player character lands after jumping, the fall animation does not switch back to the running animation, unless another input is pressed.
I'm sure there's a more sensible way to organise all this, but like I said, still getting to grips with it.
Can anyone help me with this?
`extends CharacterBody2D
var health = 10
var SPEED = 190.0
const JUMP_VELOCITY = -260.0
Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
@onready var anim = $AnimatedSprite2D
@onready var all_interactions = []
@onready var interactlabel = $"Interaction Components/InteractLabel"
@onready var actionable_finder: Area2D = $"Interaction Components/ActionableFinder"
func _physics_process(delta):
Add the gravity.
if not is_on_floor():
velocity.y += gravity * delta
if velocity.y > 0:
anim.play("Fall")
move_and_slide()
if health <= 0:
queue_free()
get_tree().change_scene_to_file("res://main.tscn")
Initiate conversation with actionables
func unhandled_input(event: InputEvent) -> void:
if Input.is_action_just_pressed("ui_accept"):
var actionables = actionable_finder.get_overlapping_areas()
if actionables.size() > 0:
actionables[0].action()
velocity.y = 0
velocity.x = 0
anim.play("Idle")
return
Get the input direction and handle the movement/deceleration.
var direction = Input.get_axis("ui_left", "ui_right")
if direction == -1:
get_node("AnimatedSprite2D").flip_h = true
elif direction == 1:
get_node("AnimatedSprite2D").flip_h = false
if direction:
velocity.x = direction * SPEED
if velocity.y == 0:
anim.play("Run")
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
if velocity.y == 0:
anim.play("Idle")
# Handle Jump.
if Input.is_action_just_pressed("ui_up") and is_on_floor():
velocity.y = JUMP_VELOCITY
anim.play("Jump")
else:
if velocity.y > 0:
anim.play("Fall")`