So when I press and hold the jump action or any action afterwards character falls fast, but I just press jump and let go he slowly falls to ground. Secondary question is why does my full animation not play when jumping/attacking?
Here’s the code so far…
extends CharacterBody2D
const speed = 300
const max_speed = 400
const jump = -500
const friction = 500
const gravity = 50
var input = Vector2.ZERO
var health = 100
func _ready():
print(“ready”)
pass
func _physics_process(delta):
input = get_input()
position += velocity * delta
Thank you!! that worked like a charm! Now what can I do to stop this physics_process from cutting my jump and attack animation short? If you don’t mind pointing me in the right direction.
This looks like the case you need to lock the animation for not start other animations until the selected one finishes, you can do something like that:
# Create a variable to store if anim is locked
var is_anim_locked := false
func play_animation_with_lock(p_anim_name: String, p_lock: bool) -> void:
# Same animation, do nothing
if $animation.current_animation == p_anim_name:
return
# Is doing some animation you don't want to cancel
if is_anim_locked:
return
is_anim_locked = p_lock
$animation.play(p_anim_name)
# If lock is true, only unlock after the animation ends
if p_lock:
await $animation.finished
is_anim_locked = false
# So you can call for animations what you want to lock like the attack or the jump:
play_animation_with_lock("attack", true)
# And for others like moving/idle you call
play_animation_with_lock("walking", false)
Okay so it seems the “current_animation” property is for the Animation Player. I should have specified that I was using Animated Sprite 2D, is there an equivalent to this property for the animated sprites? if not I may just have to switch over the the Animation Player.