+2 votes

I want to have a set of about 10 different rocks in my world environment. I have added 10 sprites with texture of different rocks and attach a Static Body + CollisonShape2D to each one of the sprites.

If I put the 10 sprites as nodes directly with the player node inside a Ysort under the world scene, the Y sorting works, and my player could go behind the rocks. However, if I put the 10 rocks in a separated scene (a rock scene), and instance the rock scene with the player node to the world, The Ysort does not work anymore, the player could only go behind one rock not all rocks.

I think that is because the world scene only use 1 Y coordinate from the Rock scene. My question is that, is there any setting I have to turn on to allow Godot uses all the Ysort coordinates for different CollisonShapes from an instance scenes? Thank you.

in Engine by (266 points)

1 Answer

+2 votes
Best answer

Found a solution to my problem. I put a few objects under Node2D as a scene, and when I instanced that scene to the world scene, Ysort is not working. As I have changed the Node2D to a Ysort node, and it works. Now all objects in the instanced scene works nicely with Ysort in the world scene.

by (266 points)

Thanks for following up, this helped me a couple of years later! I had a common enemy scene under base KinematicBody2D and was instancing that scene inside other scenes for the specific enemy types, under a base Node2D (i.e. my Enemy KinematicBody2D scene was placed as the first child of the Vampire Bat Node2D scene, hope that makes more sense). The Node2D position was not tracking, but the child KinematicBody2D was. Changed the Node2D to a Ysort, works fine now. Hopefully it doesn't cause other issues later, don't know why it would though.

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.