Child node from external scene does not follow parent transforms

Godot Version 4.4.1

Currently i have a RayCast3D node that is not following the parent transform and just stays in place. The RayCast3D node is a child within scene B, and scene B is then a child of scene A. Whenever scene A transforms, the instanced RayCast stays in place and does not follow scene A.

the white line is the raycast in question

The parents here are Node rather than a derived type (e.g. Node3D) with position.

2 Likes

Yes, this.

Every node between your Player and RayCast3D nodes need to be of type derived from the Node3D, otherwise the transform is lost. Both PlayerInventoryComponent and WeaponsManager nodes are of type Node, which don’t have the transform.

If you don’t want to change your scene’s structure, you could just copy the transform of the Player’s node to your RayCast3D node each frame, doing something like that:

func _physics_process(_delta: float) -> void:
	raycast.transform = player.transform

But you need to test it thoroughly, as it might have some weird behavior, and potentially also impact the performance.

Or you can reparent the RayCast3D to the Player node directly at the start of the scene

func _ready() -> void:
	raycast.reparent(player)
1 Like

that was my suspicion, though i had thought that RayCast3D had its own transforms. Thinking about it, RayCast3D gets its transform values from the base node, which has none. changing both parent nodes to Node3D has solved the issue. Thanks!

Well, it does have its own transform, every Node3D has a transform. But if it’s a direct child of a Node, its transform will be reset to Transform3D.IDENTITY, which has no translation, no rotation and a uniform scale of 1.0 and it won’t inherit any transformations from its parent’s parents.

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