Collision shape on CanvasLayer doesn't stay in the same place?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By brikica

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.

:bust_in_silhouette: Reply From: Zylann

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.

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

brikica | 2019-09-18 10:49

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.

Zylann | 2019-09-18 17:39