Hi out there
I hope you could help me with better coding:
I have kind of a 3D Game. I need to jump out of a scene into another, and then jump back to the point where I left the first scene. So I made the following scripts:
In the Autoload Script I wrote:
––––––––––––––––––>
var new_position_x = 0
var new_position_y = 0
var new_position_z = 0
<––––––––––––––––––––
In the Player Script I wrote:
–––––––––––––––––––>
func _ready() -> void:
global_transform.origin.x = $"/root/SAVEGAME".new_position_x
global_transform.origin.y = $"/root/SAVEGAME".new_position_y
global_transform.origin.z = $"/root/SAVEGAME".new_position_z
<–––––––––––––––––––
and in the script, where the scene changing happens, I wrote:
–––––––––––––––––––>
func _on_Area_body_entered(body: Node) -> void:
$"/root/SAVEGAME".new_position_x = $"Something".global_transform.origin.x
$"/root/SAVEGAME".new_position_y = $"Something".global_transform.origin.y
$"/root/SAVEGAME".new_position_z = $"Something".global_transform.origin.z
get_tree().change_scene("res://src/test.tscn")
<––––––––––––––––––––
"Something" is a static body that contains the area for the signal.
This really works. But it seems to me to be very bad coding. Is there a more elegant way to write this?
Thanks for thinking
best regards
tellheim