Reputation: 11
wont work bidirectionally to make world environment scenes to the levels link with atmosphere change, here is the code
`
extends Spatial
#RedFell.gd
export onready var Forest = $"/root/GlobalWorldEnvironment"
export onready var RedFell = $"/root/RedFellEnvironment"
signal player_entered_forest
func _ready():
var player_desert = get_tree().get_root().find_node("RedFell", true, false)
player_desert.connect("player_entered_forest",self, "_player_entered_desert")
func _on_DesertArea_body_entered(body):
if body.is_in_group("Player"):
Forest.environment = RedFell.environment
emit_signal("player_entered_forest")
print(body)
func _on_DesertArea_body_exited(body):
if body.is_in_group("Player"):
pass
func _player_entered_desert():
print("Player entered Desert")
Forest.environment = RedFell.environment
currently this changes the forest level to the desert atmosphere world environment, but cannot make it bidirectional with this
extends Spatial
##Forest.gd
export onready var Forest = $"/root/GlobalWorldEnvironment"
export onready var RedFell = $"/root/RedFellEnvironment"
signal player_entered_desert
func _ready():
var player_desert = get_tree().get_root().find_node("RedFell", true, false)
player_desert.connect("player_entered_desert",self, "_player_entered_forest")
func _on_ForestArea_body_entered(body):
if body.is_in_group("Player"):
RedFell.environment = Forest.environment
emit_signal("player_entered_desert")
func _on_ForestArea_body_exited(body):
if body.is_in_group("Player"):
pass
func _player_entered_forest():
print("Player entered Desert")
Forest.environment = RedFell.environment
` I've been trying to get this work but it doesn't change back to the forest when walking back into the forest level
Upvotes: 0
Views: 118
Reputation: 40295
It seems to me that you are losing the reference to the environment in your attempt to swap them.
Store the environments to resource files, and load
or preload
the one you want instead:
$"/root/GlobalWorldEnvironment".environment = preload("res://path/to/forest_enviroment.tres")
Upvotes: 0