0 votes

I made a simple infinite game.
I've got a CanvasLayer that has the background on it.

I'm trying to close off the game on either side so that the player can't escape the screen.

My thought was putting a StaticBody2D as a child of the CanvasLayer and then attaching a CollisionShape2D.

However the collision shape doesn't stay glued to the CanvasLayer, instead it just moves normally with the camera.

Hyelp.

asked Sep 14, 2019 in Engine by brikica (17 points)

1 Answer

0 votes

CanvasLayers make things inside them to render independent from camera, but this doesn't seem apply to physics. I would advise to prefer CanvasLayer only for GUI, and put camera and world objects outside of them.

answered Sep 16, 2019 by Zylann (22,041 points)

So how do you think I could do the barriers around the game the easiest?

I made a simple infinite game.

I'm trying to close off the game on either side so that the player can't escape the screen.

So your game isn't infinite? I don't understand... what do you want to do?
If you want the camera to stay centered on the character, make it child of it or align it with a script.
If you want the game world to have finite barriers, don't use CanvasLayer, just drop some colliders on the edges.
In any case I would not recommended to use CanvasLayer for objects that move inside the game world, this node is mainly useful for entirely separate things such as GUI and special situations depending on the type of game.

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.