Godot Version
v4.4.1.stable.mono.official [49a5bc7b6]
Question
This is the asset i am using, I am in a game Jam so i have to understand this, learn about how to fix this. I have set up the animation tree and made it work, but i’m not sure about how to add it in the grid shown exactly bellow, I know how to set it up for Right-Left-Down, but the asset is like Right_Up-Right_left-Down_left if that does make sense.
I have tried to fix it, but to no avail. One other issue is i’m not sure how to make good changes between the states, but this is what i have done. Idle goes to walking ect, Idle works and the cycle works Attacking works as well. Damage isn’t added yet and will be once i fix the and make the enemy tomorrow. I will also attach the player movement as it uses velocity to see if the player is idle. I am realy confused and will attach anything that you need.
On a unrealed topic which isn’t as important, do you know any good tutorials on how pathfinding works and set enemy spawning works(My first time using Godot for a project and its a GAME JAM)
extends Node
@onready var anim_tree: AnimationTree = $/root/World/Player/Player_AnimationTree
@onready var playback = anim_tree.get("parameters/playback")
@onready var body = get_parent() as CharacterBody2D
var was_attacking = false
var attack_timer := 0.0
const ATTACK_DURATION = 0.5
# A small threshold to filter out tiny movements.
const MOVE_THRESHOLD = 5.0
func _ready():
anim_tree.active = true
func _process(delta):
# Attack logic: if attack is triggered, lock in the Attacking state.
if Input.is_action_just_pressed("attack") and !was_attacking:
was_attacking = true
attack_timer = ATTACK_DURATION
playback.travel("Attacking")
# Reduce the attack timer and reset the flag when done.
if was_attacking:
attack_timer -= delta
if attack_timer <= 0:
was_attacking = false
# If attacking, we don’t change the movement animations.
if was_attacking:
return
# Determine movement-based state transitions based on velocity.
if body.velocity.length() > MOVE_THRESHOLD:
if playback.get_current_node() != "Walking":
playback.travel("Walking")
else:
if playback.get_current_node() != "Idle":
playback.travel("Idle")
And the Player movement script
extends CharacterBody2D
const speed = 50
const accel = 2
var input:Vector2
func get_input():
input.x = Input.get_action_strength("right") - Input.get_action_strength("left")
input.y = Input.get_action_strength("down") - Input.get_action_strength("up")
return input.normalized()
func _physics_process(delta):
var player_input = get_input()
if player_input != Vector2.ZERO:
velocity = velocity.lerp(player_input * speed, delta * accel)
else:
# Snap to 0 quickly when no input
velocity = velocity.lerp(Vector2.ZERO, delta * accel * 2)
move_and_slide()
I thank all of you in advance for trying to help.