#Need help with Shrinking Plant system

5 messages · Page 1 of 1 (latest)

verbal ocean
#

Here's how I want it to work: when standing on the plant with the player, it should play the "plant.shrink" animation, and when the player gets off, it should play the "plant.reset" animation. But if the player gets off before the "plant.shrink" animation finishes, the "plant.shrink" animation still should finish before playing the "plant.reset" animation. Once the "plant.reset" animation is finished, it should stay on that last frame and not play any animation.

Here is my hierarchy: StaticBody2D at the root, an Area2D underneath with a CollisionShape2D inside (this will check if the player is standing on the plant {checks if player on floor while touching the area}), another CollisionShape2D under the root, this is the collision itself the player will be able to stand on, the animation shrinks it so it doesn't need to be worried about in code, a Skeleton2D for the display sprites and an AnimationPlayer for the animations.

Any help?

fading dirge
#

Sounds like you need to use a state machine/state chart

#

What exactly do you need help with? Seems like you have all the pieces you need.

verbal ocean
#

I can't figure out the code for it, been trying for days, that's why I posted here so hopefully someone has a solution

cosmic holly
#
var shrinking: bool
var queue_reset: bool

func _on_player_enter(): #Area2D signal
  play_shrink_animation()
  shrinking = true

func _on_player_exit():  #Area2D signal
  queue_reset = true
  plant_reset():

func _on_animation_finished(anim_name): #AnimationPlayer signal
  if anim_name == "plank_shrink":
    shrinking = false
    plant_reset():

func plant_reset():
    if shrinking == false and queue_reset == true
    play_reset_animation()
    queue_reset == false