0 votes

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))
Godot version 3.4.2
in Engine by (28 points)

1 Answer

+1 vote

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. :)

by (1,789 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.