Weird behavior with Vector2.map_to_world() conversion

MoltenheadMoltenhead Posts: 3Member
edited October 8 in Programming

Hi!
Godot seems to be glitching out while using map_to_world() conversion within a tilemap extension object
here's the problem :
I've got this bit of code
print(cell_target)
print(map_to_world(cell_target))
executed each time an actor is moving from a cell to another
in all direction followups vector 2 are coresponding
(x,y) & (x,y) * 64
(2,2) & (128,128)
(1,1) & (64,64)
(1,4) & (64, 256)
...
conversion works
but each time the actors moves one cell down then directly one cell right, then "undoing" previous move (so literality going the inverted last vector way using Vector2.rotate(PI))
it returns (x,y) & (x,y-1)*64
example (2,2) & (128, 64)
which should return (2,2) & (128,128)
any idea what is causing this ?
here's what I got

what is realy weird is that the "undoing" is starting this behaviour, but it shouldn't has any impact ; since the vector it returns is transformed before passing through this last bit of code. And the code that transforms it is the same for the normal moves, so normal moves should behave the same if it was related.
I realy don't get it

steps to reproduce :
1. create a Tileset object
2. add a Node2D object as child of 1.
3. apend a script to 2. that moves its position form cell to cell with ui_inputs using direction and position incrementation using map_to_world()
4. add code to store sorted move direction within an array
5. add undo function by just inverting last direction input stored
6. use 3. with 5. to move back 2.
7. go one cell down then one cell right then undo
8. object is going (-1, -1) instead of (-1, 0) and world_to_map() returns (x, y-1) if target position is (x, y)

I'll add a repo' soon.

P.S: I could resovle this simulating the conversion with a self made method. But I'd rather prefer understanding why this is happening...

Tagged:

Tags :

Answers

  • MoltenheadMoltenhead Posts: 3Member
    edited October 12 Answer ✓

    Found the problem but didn't took the time to post:

    The console is lying!
    printing world_to_map() returned value always shows int values, but it can eventualy be a float in some specific contexts.
    The problem came frome a bad way of inverting the vector:
    Vector2.rotate(Pi), instead of the way simpler Vector2 * -1.

    So the first method returns floats that are very near the wanted result, but once transformed with map_to_world() it floor the cell positions then multiply by Tileset.cell_size.

    So (1, 1.99999999...) gets transformed into (1, 1) instead of (1,2) then multiplied by cell_size.

    Case closed.

Sign In or Register to comment.