0 votes

worldtomap work if scale == Vector2(1, 1), but its don't work if scale != Vector2(1, 1)

Godot version 4.0.alpha4.official
in Engine by (159 points)

1 Answer

0 votes

Hard to know what's wrong without seeing your code, but my guess is you are passing a world position to world_to_map.
I regret to inform you this method doesn't expect a true "world-space" position. Instead it expects a position local to the tilemap. If the tilemap is moved, scaled or rotated, you have to first convert your position to local space, and only then, you can call world_to_map:

var tile_pos = tilemap.world_to_map(tilemap.to_local(world_position))

Check the documentation: https://docs.godotengine.org/en/stable/classes/class_tilemap.html#class-tilemap-method-world-to-map

by (29,092 points)
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.