|
|
|
|
Reply From: |
yrtv |
From TileMap.world_to_map()
Returns the tilemap (grid-based) coordinates corresponding to the given local position.
To use this with a global position, first determine the local position with Node2D.to_local:
var local_position = my_tilemap.to_local(global_position)
var map_position = my_tilemap.world_to_map(local_position)
If BreakPalmPosition global position, then convert it first.
Just a quick question/more details. The Saplings is what my tilemap is called and that line of code is from the palm script itself. im not using Global_position because then i would get the position of every palm i want just the one that im breaking ive figured out that part. And what is the
var local_position = my_tilemap.to_local(global_position)
var map_position = my_tilemap.world_to_map(local_position)
script attached to, the tilemap or the palm or something completely different?
sorry again for being an idiotic noob
Superkrypet | 2021-10-01 13:54
I just quoted relevant part of documentation. Script is example from documentation, it assumes script is attached to TileMap.
If I understand your code correctly, then:
In Singleton:
Saplings.BreakPalmPosition = global_position
In TileMap
BreakPalm = world_to_map(to_local(BreakPalmPosition))
Yes Exactly.
only problem is that it dosent work, instead it returns an error:
Invalid Type of function to local in base tilemap. cannot convert from nil to vector2
Superkrypet | 2021-10-02 11:16
Try converting position before passing to TileMap
Saplings.BreakPalmPosition = Saplings.to_local(position)
And use Vector2.INF
instead of null
in TileMap
extends TileMap
var BreakPalmPosition = Vector2.INF
var BreakPalm
func _process(delta):
if BreakPalmPosition != Vector2.INF:
BreakPalm = world_to_map(BreakPalmPosition)
set_cellv(BreakPalm, 0)
BreakPalmPosition = Vector2.INF
getting closer:
Invalid type in function world_to_map in base TileMap
Yeah, that one was annoying
Superkrypet | 2021-10-03 06:54
Actually No. I forgot the INF detail.
With that code where back at the start. No Errors, No action and nothing working
somehow i feel like im just wastin your time
Superkrypet | 2021-10-03 20:52
Debugger is your friend. Check BreakPalmPosition
on every step of it;s way to Tilemap. Make sure it’s global 2d position all the way until Tilemap.to_local()
call