0 votes

I have multiple "gate" node that are attached to a single script when spawned into the game. The code is below:

using Godot;
using System;

public class gate : StaticBody2D
{
    //Required Nodes.
    private world gamewrld;
    private audioManager audio;

    //Local nodes.
    private AnimationPlayer anim;
    private Area2D plyrDetect;

    //Other variables.
    public bool open = false;
    public bool plyrCheck = false;
    public int playing = 0;
    public bool needClosed = false;
    private Godot.Collections.Array bodies = new Godot.Collections.Array {};

    public override void _Ready()
    {
        //Grab all required nodes.
        audio = (audioManager)GetNode("/root/audioManager");
        gamewrld = GetParent().GetParent() as world;
        anim = GetChild(1) as AnimationPlayer;
        plyrDetect = GetChild(3) as Area2D;

        if (Name.Contains("hGateFull") || Name.Contains("vGateFull")) {
            needClosed = true;
        }
    }

    public override void _Process(float delta)
    {
        //Check to see if any bodies are overlapping the gate.
        bodies = plyrDetect.GetOverlappingBodies();

        if (bodies.Count > 0 && !plyrCheck) {
            var plyr = bodies[0] as player;
            //Pause player movement and animations.
            plyr.ctrl = false;
            plyr.pauseResume(true);
            audio.playSound("gate");
            anim.Play("open");
            plyrCheck = true;
        }
    }

    public void onAnimDone(string which) {
        GD.Print("Animation is done.");
    }
}

Everything works EXCEPT the animation. (It sends out the signal that the animation is finished even though the sprite itself DOESN'T change). I've checked and rechecked but the darn thing just won't animate when the player slaps into it. Any ideas?

Edit: Sorry, didn't mean to double post.

Godot version 3.4.4 Mono Stable
in Engine by (211 points)

Please log in or register to answer this question.

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 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 webmaster@godotengine.org with your username.