No just the part i use for attack animation (no collision detection is yet in place). I just tried replacing the attack animation with one of the running animation and it works fine in that case. Here is the whole script:
extends CharacterBody2D
@onready var animation = $AnimationPlayer @onready var sprite_2d = $Sprite2D
var speed = 400 # speed in pixels/sec
var idelAnimation = “Idel_Down” #for knowing which idel animation to play depending on direction
var isLeft = false #for knowing if to flip sprite
func _input(event):
if event.is_action_pressed(“Attack”):
doAttack()
func doAttack():
animation.play(“Attack_Sides”)
func _physics_process(delta):
# Animations :
var direction = Input.get_vector(“Left”, “Right”, “Up”, “Down”)
velocity = direction * speed
looking at if velocity.x != 0 and velocity.y == 0: here. Maybe it starts playing but gets overwritten by the other animations? “Run_Sides” would overwrite it if you weren’t moving. Try commenting those lines out for now and see if it works
I just commented out all other animation line apart from the attack ones. Now it does start playing, but doesn’t stop. Thank you for all your help btw hope this isn’t bothersome for you. What would be the best way to do a attack animation together with other animations, is there a good simple example somewhere?
Look around for open source 2D projects like platformer demos, Those should have the cod for all of that. The way I would do it would probably be a bad one.
Thank you for all your help! I managed to fix it now! Here is the final script, it may not be the most perfect or optimized but heyyyy.
extends CharacterBody2D
@onready var animation = $AnimationPlayer @onready var sprite_2d = $Sprite2D
var speed = 400 # speed in pixels/sec
var idelAnimation = “Idel_Down” #for knowing which idel animation to play depending on direction
var isLeft = false #for knowing if to flip sprite
var isAttacking = false
func _input(event):
if event.is_action_pressed(“Attack”):
doAttack()
No problem! btw for code formatting there’s either the icon above the text editor (</>) or you can just use pastebin for bigger scripts. If you do use pastebin turn on syntax highlighting and select GDscript. Good luck with your game!