0 votes

Hello!

I am doing my first project in Godot, and I have a little problem.
I have some objects that randomly come out of an ItemList, and are placed on a ribbon (it's a sprite)

And I want that when these objects are generated randomly, they cannot come out on top of each other, and others either that when I move them, they can not move on top of others

My idea was to add a rigidbody and a collision shape to the item list, but I see that I am incorrect.

What can I do to fix that they don't appear on top of each other? Thanks

Godot version 3.3.2
in Engine by (12 points)

1 Answer

+2 votes

The YSort node can help you. You can add the items you spawn as children of this node. It will automatically place them based on their Y-axis value.

by (345 points)

I thought I haven't explained it correctly.

I have many items, generated by an item list, shown in a small part of the screen. These are generated randomly on the map, and I want to, when they appeared on the screen, can`t be one on top of the other.

In the example you send me, the trees are created by the author, and aren“t created randomly like I`m requesting

Thanks for the answer anyways

Greetings to you

Maybe you can try to spawn an area2d node first to detect whether there is an item. If the signal returns the item, then skip this position and random another one.

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.