Animation playing first frame only (enum state)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Halfpixel

Hello, new to godot and programming.
I have two states of an enemy (patrol/chase) when my chase state is running my animated sprite is stuck at the first frame only.
Eventhough the enemy is chasing the player (in chase state).

func _physics_process(delta):
	if state == "patrol" or $Detection_area/CollisionShape2D.disabled == false:
#		$"Patrol")
	if state == "chase":
#		$"Chase")
:bust_in_silhouette: Reply From: Inces

You can’t play animations in physics process. This will make animation start from 0 every physics frame, so it will never get to 2nd frame of niamation. You need to run this kind of code once. You can use signals, setget, boolean property blocker and many more. For state machine I recommend setget.

I think I understand, however the animation in the patrol state plays fully while the animation in the chase state doesn’t, shouldn’t both start at 0 every physics frame by the same rule?
I’m a little confused about this part.

Halfpixel | 2022-10-23 16:17

Yes they should, so I guess Your patrol state only takes 1 frame and is immadiately changed to some other state with no animation

Inces | 2022-10-23 17:17