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.


in Engine by (18 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.

by (28,984 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 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 [email protected] with your username.