This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

I am trying to make realistic animations and I cant seem to get the animation to reset after the player steps off the grass.

    extends Area2D


func _physics_process(delta):
    var bodies = get_overlapping_bodies()
    for body in bodies:
        if body.name == "Player":
            $GrassAnim.play("Stepped")
        else:
            $GrassAnim.play("Normal")

how should i fix this?

Godot version 3.3.4
in Engine by (37 points)

1 Answer

0 votes

You iterate thru total collision count. You made it so when player is colliding with the grass it plays STEPPED, but when players is not colliding - nothing happens, because there is no collision at all. Your NORMAL animation only plays when something other than player collides with it.
Another problem You have is that You force to play animation every frame. That means that as long as there is collision those animations reset every frame, never getting to end of animation loop.

I would use signals to solve this problem. On area enetered signal will make STEPPED play, on area exited - NORMAL. You can loop animations You want to repeat, or control loop using animation_ended signal

by (8,188 points)
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.