How to spawn objects in 3D

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

I have been working on a VR game and was trying to allow the player to pick up blocks. I looked at the documentation and found it too be very complex and was hoping to make a simpler solution. However, for the life of me I cannot figure out how to spawn in an object in 3D

Here is my code

func _on_Grab_area_entered(area):
		var currentobject = null
		object = area.name
		var heldobject = load("res://" + object + ".tscn")
		var heldobject = load("res://Box.tscn")
		currentobject = heldobject.instance()
		currentobject.translation = $Position3D
		add_child(currentobject)

The problem happens with “currentobject.translation = $Position3D” I can’t figure out what to use instead of Translation as Position doesn’t work either. Something that might be helpful is that the object I’m trying to spawn is a Area, I had wanted it to be a Rigidbody but changed it to hopefully fix the problem.

Thanks!

:bust_in_silhouette: Reply From: Wakatta

Change

currentobject.translation = $Position3D

to

currentobject.global_transform.origin = $Position3D.global_transform.origin

or

currentobject.translation = $Position3D.translation

Thank you, the first one worked :smiley:

CreekWorks | 2021-02-26 21:35