Odd issue with Animatable Body and child nodes

Godot Version v4.2.1.stable

Question

I’ve encountered an unexpected behavior with an AnimatableBody and certain child nodes.
It’s a bit hard to explain but I’ll try my best:

I have a custom class that controls a moving Platform, based on an AnimatableBody3D.

This platform can be controlled by a button (GenericButton), also a custom class that is a child of the platform (see image). This one in this case is also derived from an AnimatableBody3D.

image

I want this button to move with the platform when it moves, yet here it’s where it gets complicated:

My project uses a raycast-based interaction system. Any objects that I want to interact with need to be on collision layer 2.

As I don’t want to interact with the platform node, I set it only to layer 1.
The GenericButton is on layer 1 and 2.

In game when I activate the button, the platform moves, and so does seemingly the GenericButton, except I notice that seemingly the attached COllusionShape3D of the GenericButton stays in place.
All the other objects seem to move as expected.

This behavior does NOT occur, if I set the platform’s collision to layer 1 and 2.
Unfortunately, if I set my platform like that, my system picks up the whole platform as the interaction trigger, practically making all it’s collision shapes work like the button.

Is there a way to get the GenericButton’s collision shape to move with the rest of it / not have it stay in place for some reason?

Thanks in advance!

PS: I’m ussing tweens to move the platform. And the AnimatableBody3D’s all have Sync to Physics turned on.

It looks like the AnimatableBody3D (specifically the button) isn’t syncing it’s new position to the physics server when it’s parent’s transform updates, which is almost certainly a bug.
Anyway if you just pretend to update the inner body’s position it looks like if fixes it:

@onready var starting_pos: = position
func _physics_process(_delta: float) -> void:
	position = starting_pos

it’s too smart for our tricks if we do position = position so I had to save the position from the start and use that so it would actually try saving the position heh.

if you need to be a little more optimal you would want to only do that kind of thing if the plaform is actually moving that frame

edit: it’s this bug CollisionShape does not update moving AnimatableBody3D? · Issue #67257 · godotengine/godot · GitHub
looks like if you just set sync_to_physics off on the internal body (the button) that will also fix it, the collision body might be a frame behind but I doubt that would ever be noticible

1 Like

Oh I see, thanks for this insight!

Actually just turning sync to physics off on the child node (button) worked well for my case.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.