Advertisement
Kijan

Untitled

Feb 20th, 2019
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.62 KB | None | 0 0
  1. for i=2, count do
  2.                 newObj = nil
  3.                 if positions ~= nil then
  4.                     newObj = object.clone({position = positions[i]})
  5.                 else
  6.                     newObj = object.clone({position = {x = math.random(0, xMax) * step + start.x, y = start.y, z = math.random(0, zMax) * step + start.z}})
  7.                 end
  8.                 Wait.condition(function() terrainBag.putObject(newObj) end, function() return checkLoaded(newObj) end)
  9.                 Wait.condition(function() checkBounds(object) end, function() return checkLoaded(object) end)
  10.             end
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23. function checkBounds(object)
  24.                 local bounds = object.getBounds()
  25.                 local pos = object.getPosition()
  26.                 local hitList = Physics.cast({
  27.                     origin          = {pos.x, pos.y, pos.z},
  28.                     direction       = {0,-1,0},
  29.                     type                = 3,
  30.                     size                = {bounds.size.x, bounds.size.y, bounds.size.z},
  31.                     max_distance    = 5,
  32.                     debug               = true
  33.                 })
  34.                 for _, entry in ipairs(hitList) do
  35.                     local offsetX = 0.905
  36.                     local name = entry.hit_object.getName()
  37.                     print(name)
  38.                     if name ~= object.getName() and name ~= "Table" then
  39.                         local bounds = entry.hit_object.getBounds()
  40.                         local new_pos = {bounds.center.x - offsetX * 6, 1.5, pos.z}
  41.                         object.setPosition(new_pos)
  42.                     end
  43.                 end
  44. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement