How to return an Spatial object to its initial position?

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

I’m making a simple game and also learning. I’m trying to do that when thisAnimatedSprite3- Spatial node arrives to z = -40 it should move to 40 again, like its starting point.

extends AnimatedSprite3D

# Called when the node enters the scene tree for the first time.
var flySpeed = 5.0
var yAngle = 0.0
var voladorPosition = self.translation


func _ready():
	pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):

	print(voladorPosition)

	
	if(voladorPosition.z == -40.0):
		voladorPosition = 40

	yAngle += 0.1
	translate(Vector3(delta*flySpeed, clamp(sin(yAngle)* PI, -0.05, 0.05), 0))
	
:bust_in_silhouette: Reply From: DaddyMonster

You didn’t say under what circumstances would you like the the obj to return to its initial position? Regardless, you can hold the spawn position an attribute / member variable (eg. var spawn_position = Vector3.ZERO) or you could use a spatial if you prefer.

Then whenever you’d like to reset the position you could write global_transform.origin = spawn_position

Bish bash bosh. Job done. :slight_smile: