#I don't even know how to explain this
13 messages · Page 1 of 1 (latest)
When it plays the idle animation, for 1 frame it changes to other
extends CharacterBody2D
var target_zoom = Vector2(1, 1)
@export var speed = 200
@export var friction = 1
@export var acceleration = 0.1
@onready var sprite_2d: Sprite2D = $Sprite2D
var facing = "down"
func _ready():
target_zoom = $Camera2D.zoom
func get_input():
if Input.is_action_just_released("ZoomIn"):
if target_zoom.x <= 3.5:
target_zoom += Vector2(0.5, 0.5)
elif Input.is_action_just_released("ZoomOut"):
if target_zoom.x >= 2.5:
target_zoom -= Vector2(0.5, 0.5)
var input = Vector2()
if Input.is_action_pressed('Walk_right'):
input.x += 1
if Input.is_action_pressed('Walk_left'):
input.x -= 1
if Input.is_action_pressed('Walk_down'):
input.y += 1
if Input.is_action_pressed('Walk_up'):
input.y -= 1
return input
func _physics_process(delta):
var direction = get_input()
if direction.length() > 0:
velocity = velocity.lerp(direction.normalized() * speed, acceleration)
else:
velocity = velocity.lerp(Vector2.ZERO, friction)
move_and_slide()
$Camera2D.zoom = $Camera2D.zoom.lerp(target_zoom, 5 * delta)
if velocity.is_zero_approx():
$Sprite2D/AnimationPlayer.stop()
$Sprite2D/AnimationPlayer.play("idle_" + facing)
print("idle_" + facing)
print($Sprite2D/AnimationPlayer.current_animation)
else:
if velocity.x >= 1:
$Sprite2D/AnimationPlayer.play("run_side")
facing = "side"
sprite_2d.flip_h = false
elif velocity.x <= -1:
$Sprite2D/AnimationPlayer.play("run_side")
facing = "side"
sprite_2d.flip_h = true
elif velocity.y <= -1:
$Sprite2D/AnimationPlayer.play("run_up")
facing = "up"
elif velocity.y >= 1:
$Sprite2D/AnimationPlayer.play("run_down")
facing = "down"
When I face up it always plays the idle_down
but when I face down it plays idle_side
I figured out that the problem doesn't happen when I stop playing the run animations, but i still cant fix it
I cannot see any immediate issue here.
It may be an issue with the names of the animations. Remember they are case sensitive
Unfortunately that's not the problem 😦
Idk if it's ok to create animations like that
I'm using one single sprite 2d, and when i need to use an animation from other sprite i just use the texture key
That is fine.
Make sure the texture key is set properly tho
It is
Is there any chance of this being a godot 4 bug?
It makes no sense for this to be an engine bug.
i would use breakpoints to see the exact order of calls and follow the state of the animation line by line.
But idk what am i supposed to check
cuz when i debug it says that there's no problem at all