Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | wratio |
Hello. I am a beginner when it comes to Godot and GDScript, and have been trying to make a simple platformer. I have added in the jump and everything works so far, my only problem is the jumping and falling animations. The fall works ok, but the jump animation instead pauses on the first frame and doesn’t change while it is played. Here is my code attached to the player:
extends "res://Scripts/Actor.gd"
onready var animatedSprite = $AnimatedSprite
var velocity = Vector2.ZERO
var maxRun = 100
var runAccel = 800
var gravity = 1000
var maxFall = 160
var jumpForce = -160
var jumpHoldTime = 0.2
var localHoldTime = 0
func _process(delta):
var direction = sign(Input.get_action_strength(“ui_right”) - Input.get_action_strength(“ui_left”))
var onGround = global_position.y >= 160
var jumping = Input.is_action_pressed("Jump")
if jumping && onGround:
velocity.y = jumpForce
localHoldTime = jumpHoldTime
elif localHoldTime > 0:
if jumping:
velocity.y = jumpForce
else:
localHoldTime = 0
localHoldTime -= delta
if direction > 0:
animatedSprite.flip_h = false
elif direction < 0:
animatedSprite.flip_h = true
if direction != 0:
animatedSprite.play("Run")
else:
animatedSprite.play("Idle")
if !onGround:
if velocity.y < 0:
animatedSprite.play("Jump")
else:
animatedSprite.play("Fall")
velocity.x = move_toward(velocity.x, maxRun * direction, runAccel * delta)
velocity.y = move_toward(velocity.y, maxFall, gravity * delta)
moveY(velocity.y * delta)
moveX(velocity.x * delta)
(Sorry for the bad formatting)
Also, the part that handles movement is in another script.
Any help on how to fix the jump animation would be really helpful and thanks for reading