0 votes

Im making a openworld/voxel game in 3D, and want to move players around in dimensions, eg like in minecraft.
How do i make things not visible/collisions interactive from other scenes, without having to set every node's layer?

     |main scene|
   |      |      |
|scene1|scene2|scene3|
Godot version 3.3.2
in Engine by (195 points)
edited by

2 Answers

0 votes
Best answer

For performance the best method is definitely collision masking, even though you don't want to go for that option (by the way, you can shift-select multiple nodes to change their properties and layers all at once).

After setting it all in the editor up you only have to set_collision_mask_bit to false on the player for that layer mask at runtime:

Physics Layers
But there is an alternative, easier (to set up) but far less performant method which is to simply delete scenes from the Scene Tree using queue_free() and then load them back in again later:

Script-instanced Scenes
Apart from all the conditions driving this particular scene, all the code that matters for instancing is the following:

# Scene 2 (re)loading code.
scene2 = load("res://Scene2.tscn").instance()  # (re)load the scene
add_child(sceen2)  # 'add as a child' of the main scene
scene1.queue_free()  # delete the current scene

# Scene 1 reloading code.
scene1 = load("res://Scene1.tscn").instance()
add_child(sceen1)
scene2.queue_free()

I have uploaded the full demo from this on Github if you want to try it out.

And performance naturally won't be negatively affecting most machines but you may need to implement loading screens on slower devices.

Hope it helps!

by (1,002 points)
selected by
0 votes

I'm not sure abut your idea, but in minecraft it's dimensions are completly separated from one another, are they?

So if I get it right, that you want to have all dimensions 'alive' at once, I think it's would be better to simple have only one and when player teleports you simple load a new scene with that dimension while also storing the sate of the current one and freeing it.

So in any given moment there should not be 2 overlaping dimensions that don't even need to interact.

by (210 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 Frequently asked questions and 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.