0
\$\begingroup\$

I am working on a game where the player needs to open a door using a button.

A door open animation plays when the player clicks the button which triggers a keymap. So I used:

extends StaticBody3D @onready var anim = $AnimationPlayer @onready var col = $CollisionShape3D2 func _physics_process(delta: float) -> void: if Input.is_action_pressed("openLevel"): anim.play("doorAnim") col.disabled = true 

But it starts playing automatically and keeps playing. I only want it to play the animation when the player clicks the button triggering "openLevel" keymap.

How do I fix this?

\$\endgroup\$

2 Answers 2

2
\$\begingroup\$

The first thing that comes to my mind is that you have the animation configured as Autoplay and loop. The second, some logic error in the code that triggers openLevel at the wrong time.

\$\endgroup\$
0
\$\begingroup\$

There was a logic error. As I added left mouse button to trigger the animation. Since "mouse from touch" was enabled in mobile the "openLevel" keymap would automatically trigger when looking around because touching the screen emulates left mouse button. Changing the key fixes the problem.

\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.