Cannot seem to get proper translation or transform.origin of an instanced child scene node

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Sir_Skurpsalot

I’m working on part of a script for my player in a 3d fps that is supposed to move the camera smoothly from a default position to an aiming position behind the gun upon pressing the aim button. The aiming position is a spatial node called GunCam that is a child in a pistol scene that is instanced and made of a child of the StrongHand bone attachment node on the player. The problem is when I press the aim button the camera seems to go the position that the node is in in the pistol scene (ie, on the floor), not to where it is in the current scene.

func _physics_process(delta):
if aiming == true:
	gunCam = $Model/Armature/Skeleton/StrongHand/Model/GunCam
	end = gunCam.get_translation()
	end = camAttachment.get_translation()

var camPos = camera1.get_translation()
var start = camPos
var lerpPos = start.linear_interpolate(end, delta * 20)
camPos = lerpPos
:bust_in_silhouette: Reply From: kidscancode

translation (and transform) is in local coordinates, so it’s relative to the node’s parent. You probably want global coordinates so use global_transform.origin.

Thanks for replying.

Changing everything to global transforms puts the camera in a weird place that is not at all connected to the player

Sir_Skurpsalot | 2019-08-17 04:38

For more clarity I can use the script on ANY node that is a part of the original player scene/object, like his hand, etc and the script works exactly as intended. It’s only on the instanced pistol object that it seems unable to get the correct point, it seems like it’s sending the camera to an offset of where the GunCam spatial is in the pistol.tscn file instead, on the floor, even though I can see that the pistol is located in his hand where it should be, and if I add a mesh to the GunCam spatial I can see that it is in the right location as well.

Sir_Skurpsalot | 2019-08-17 05:39