0 votes

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:
#       $AnimatedSprite.play("Patrol")

    if state == "chase":
#       $AnimatedSprite.play("Chase")
Godot version 3.2
in Engine by (25 points)

1 Answer

0 votes

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.

by (8,101 points)

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.

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.