|
|
|
|
Reply From: |
Inces |
I already answerde this question :
https://forum.godotengine.org/121904/how-can-i-detect-cell-tile-around-my-player
was something wrong with this ?
no, that the right way do detect all tile around my player/object, thank you.
but this time, i want to find all tile under area2d,
example if i use other shape other than circleShape like star shape, i want all tile under that shape can be change,
so first i need all tile position under that aread2d shape. i already put collison on that tile.
potatobanana | 2021-12-05 15:48
Oh, that is much more complicated task
TileMap is not natural to detect detailed collisions. If You really need every possible custom shape to interact with tilemap like this, I would try to make a custom node to adapt shape of collision into tilemap
This node ( lets call it squarer ) should consist of Area2D and empty collision shape. When shape is chosen in your project squarer should first instance big square of smaller areas ( with small suare collision shape ) in rows and columns aligned with tilemap scale. In process() squarer will have a code to snap to tilemap - having its position modified to world_to_map of mouse cursor. Finally, on click, squarer will iterate through small square areas that are colliding with the main shape, and each of smaller square position will be a global position of tile You need.
if i understand correctly.
- make new scene
- then make area2d with single cell tile size.
- then instance that new scene on top of tile cell i want to detect( exmple cell 8, then put in world_to_map pos)
- next i can detect all it with circleShape Area2d, using area_entered
potatobanana | 2021-12-06 16:11
quite
-
Make a new scene. It is Area. We will call it Squarer. Its children :
a) Collision shape. Leave empty in editor, You will choose your shape and range by code
b) Node2D. It will be container for tiny areas later. Lets call it Container
-
Make a new scene. It will be subscene of Squarer later. It is Area. We will call it minisquare. Set its collision shape to square of tile size.
3.You will instance Squarer scene when in need, and free it when used.
In ready() it will have something like this ( pseudocode )
for x in range(-size,size)
for y in range(-size,size)
var inst = minisquare.instance() #preload it earlier
inst.position += Vector2(tile_size * x,tile_size * y)
4.IN process() Squarer will have:
var mouse = world_to_map(global_mouse_position)
global_position = map_to_world(mouse)
5.On click or press buttom Squarer will have :
var collidingtiles = []
For miniarea in get_overlapping_areas():
collidingtiles.append(miniarea.world_to_map(global_position)
This is pseudocode, so You will have to add details for syntax to work with all your references You can also make it more fluid, separating snapping function for main shape and minisquares