Page 1 of 1

[0.13.17] large objects aren't placed on the specified pos

Posted: Thu Aug 18, 2016 6:28 pm
by MrDoomah
Large object created by

Code: Select all

 surface.create_entity{name="reactor-"..tostring(dx).."x"..tostring(dy), position={left_top.position.x + dx/2 -1/2, left_top.position.y + dy/2 -1/2}, force=force} 
aren't placed on the right position:

Code: Select all

local new_reactor = surface.create_entity{name="reactor-"..tostring(dx).."x"..tostring(dy), position={left_top.position.x + dx/2 -1/2, left_top.position.y + dy/2 -1/2}, force=force}
game.players[1].print("1: x: " .. left_top.position.x + dx/2 -1/2 .. ", y: " .. left_top.position.y + dy/2 -1/2)
game.players[1].print("2: x: " .. new_reactor.position.x .. ", y: " .. new_reactor.position.y)
ImageImage

Smaller objects are placed in the correct position:
ImageImage

Re: [0.13.17] large objects aren't placed on the specified pos

Posted: Fri Aug 19, 2016 6:46 am
by posila
MrDoomah wrote:Large object created by

Code: Select all

 surface.create_entity{name="reactor-"..tostring(dx).."x"..tostring(dy), position={left_top.position.x + dx/2 -1/2, left_top.position.y + dy/2 -1/2}, force=force} 
Why -1/2?

Re: [0.13.17] large objects aren't placed on the specified pos

Posted: Fri Aug 19, 2016 11:08 am
by MrDoomah
Because the way I implemented 'left_top'. Left_top isn't part of an area, but the position of the left_top most entity underneath the entity you see in the pictures. Since these entities are 1x1 in size, the position is given in {x+0.5,y+0.5} as this is the centre of the tile the entity. To correct for this I need to subtract the 0.5 from this position. See image where I also print out the 4 corners.
Image


Does that make sense?


Edit: Adding a flag "placeable-off-grid" to the entity does seems to fix it, but I do want them to align to grid.

Re: [0.13.17] large objects aren't placed on the specified pos

Posted: Fri Aug 19, 2016 11:31 am
by posila
Ah, I see ... what bounding box has "reactor-5x5" entity defined in protoype?

Re: [0.13.17] large objects aren't placed on the specified pos

Posted: Fri Aug 19, 2016 1:58 pm
by MrDoomah
Ah whoops. I'm an idiot xD. The entities were generated by a script that made the bounding box {0.4*size,0.4*size}, so at size 5, the bounding box is 4x4 instead of 4.5x4.5-ish that I intended.