StaticBody will only go to position of parent

Godot Version

4.2.2 (Steam)

Question

I am trying to add an automatic door to my game, and it uses a staticbody3d node with a mesh and animation player as children. But for some reason, I can move the door to another location and it will work in the editor, but in-game it will only go to the position of the parent. Please help, I’m new and I don’t know what might cause this.

It would help if you could include the contents of the script that makes the door move in-game. It’s hard to debug otherwise.

Also, what do you mean by…

…it will work in the editor[…]?

Are you running the script as a tool (@tool / [Tool])?

Script for door:
extends MeshInstance3D
@onready var animator = $StaticBody3D/AnimationPlayer

var entitiesin = 0

func _on_area_3d_body_entered(body):
if body.is_in_group(“player”) or body.is_in_group(“enemy”):
animator.play(“opening”)
entitiesin += 1

func _on_area_3d_body_exited(body):
if body.is_in_group(“player”) or body.is_in_group(“enemy”) and entitiesin == 1:
animator.play(“closing”)
entitiesin -= 1

No, I am not using @tool, what I mean is in the 3D editor it will show the door where I want it but in-game it shows it in the position of it’s parent. A temporary workaround I have is to create a Node3D parent for every door in the game, but I would prefer not to.

1 Like

Okay. Your code looks fine.
This is probably a hierarchy issue.

As you mentioned, creating a Node3D parent for the door fixes the issue.
The reason this fixes it is that the animation for your door is always computed in local space. What this means is: if your animation moves the door from X (0.0) to X (1.0), it will always be relative to the parent. So…

…you need a Node3D for an animation like this. You shouldn’t see it as a big deal. As long as you make a door prefab (i.e. a saved scene), it’s not something you have to do all the time.

If you want my confident input on the structure of your door scene, please link a screenshot of that scene.