Page 1 of 1

Bug in setWorldPosition? v2.1.18

Posted: Mon Jan 19, 2015 4:20 pm
by grimMod
Hi.
Problem: When using setWorldPosition the gameobject might get wrong x and y value depending on facing.

To recreate:
Create a north facing wall at 15,15 id=dungeon_wall_01_1. It's important that it's north facing for this to work/fail.
Run this code to move it up 1 elevation (1 elevation = 3 in world):
pos = dungeon_wall_01_1:getWorldPosition() dungeon_wall_01_1:setWorldPosition(pos[1], pos[2]+3, pos[3])

Visually this looks ok - the walls jump up 1 elevation.
However, if you look at print(dungeon_wall_01_1.y) it has become 14 (moving upwards shouldnt change y-value).
This may potentially cause collision problems if you are moving gameobjects with collision.

There are more problems like this:
if moving gameobject east then gameobjects faceing east gets +1 extra in x-value. Those facing north get -1y
moving north: face east +1x face north -1y
moving south: face east +1x face south +1y
moving west: face west -1x face north -1y
moving up: face north -1y face east +1x
moving down: face north -1y face east +1x

Is this a bug or am I missing something?

Re: Bug in setWorldPosition? v2.1.18

Posted: Mon Jan 19, 2015 8:00 pm
by petri
You are moving the wall exactly on the edge between two squares, so the wall may end up in either square.

Re: Bug in setWorldPosition? v2.1.18

Posted: Mon Jan 19, 2015 10:17 pm
by grimMod
petri wrote:You are moving the wall exactly on the edge between two squares, so the wall may end up in either square.
Thanks for the reply. If will move the walls slighty towards it's correct square to avoid this.

But there's something else (or maybe connected?) with setWorldPosition.

Consider this function:

function testsetworld()
local pos
for i=1,60 do
pos = dungeon_wall_01_2:getWorldPosition()
dungeon_wall_01_2:setWorldPosition(pos[1] - 0.05, pos[2], pos[3])
end
end

I would expect it to move dungeon_wall_01_2 a total of 3 (=60*0.05). However the wall is moved 3.000183. Not much difference I know, but why the small "error"?