0 votes

Hello. I'm currently working on a procedurally generated 2d game.

I want to procedurally generate the playable area where the player is surrounded by rocks, but the rock-textures are of different sizes.

The rock textures are 1x1, 1x2, and 2x2 tiles. Currently the different sized rock-tiles overlap eachother. It seems that even tho I set the tiles collision to 2x2, the placed tile is still only 1x1. Is there a way of making the tiles not spawn if it collides with another?

I've added a screenshot to better display my problem.

image

Godot version 3.2.3
in Engine by (15 points)

1 Answer

+1 vote
Best answer

Tilemaps combine all of their tiles' collision shapes into one big collision shape. So just check if there's a shape at a certain point using Physics2DDirectSpaceState!

Alternatively, you can just check if there's a 1x2 or 2x2 tile right next to the tile you want to place the new tile on.

by (7,336 points)
selected by

Thank you for your answer, but I'm still struggling.

So I tried to use Physics2DDirectSpaceState with a raycast to detect collision, but it seems it only works inside the physicsprocess. My function for populating the map with tiles works outside of the physicsprocess.

I like the idea of using the tiles collision to decide whether a tile should be placed or not, because it can be reused for different tilemaps. But I may just have to hardcode the size of each tile and then make the code decide which tiles to skip.

Yeah maybe the second method should be used in this case

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.
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 webmaster@godotengine.org with your username.