Page 1 of 1

carefully place items

Posted: Wed Dec 10, 2014 7:45 pm
by THOM
I try to place an item very precice in my mod.
I've seen, that the Devs used for the same trick in the Library a command, that I am unfamiliar with:

torch_1:setWorldPosition(vec(53.00, 0.9, 44.5))

But I cannot figure out, what the numbers mean. Maybe (x, hight, y) But they seem to place my torch just in bigger steps - and I couldn't get it up.

Any help?

Re: carefully place items

Posted: Wed Dec 10, 2014 9:11 pm
by Phitt
Apparently setWorldPosition uses the position in game units starting from the lower left corner (x 0, y 31). And it uses the standard coordinate system, x, height, y. Each tile is 3x3 units/metres. To get the exact position of your object you can use getWorldPosition and print the values to the console.

Re: carefully place items

Posted: Wed Dec 10, 2014 10:15 pm
by Batty
Here's a simple script to adjust world position of objects:

Code: Select all

function move(entity, x, y, z)
   if findEntity(entity) then  
      local coord = findEntity(entity):getWorldPosition()
      if x then coord[1] = coord[1] + x end
      if y then coord[2] = coord[2] + y end
      if z then coord[3] = coord[3] + z end
      findEntity(entity):setWorldPosition(coord)
      print(findEntity(entity).name..' '..entity..' moved: '..iff(not x, 0, x)..', '..iff(not y, 0, y)..', '..iff(not z, 0, z))
   else
      print('no such entity: '..entity)
   end
end
Calling the function:

Code: Select all

move('rock_1', 0.3, 0, -.08)
Here's a guide to positioning, I think it's correct...
Image