Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function tocell(vec)
- return Vector3.new(math.ciel(vec.x/cellsize),math.ciel(vec.y/cellsize),math.ciel(vec.z/cellsize))
- end
- function toworld(vec)
- return (vec-Vector3.new(.5,.5,.5))*cellsize
- end
- function cellsinrange(pos,radius)
- local diameter=math.ciel((radius*2)/cellsize)
- local hdiameter=diameter*.5
- local cells={}
- for xcell=1,diameter do
- for ycell=1,diameter do
- for zcell=1,diameter do
- local cellpos=tocell(pos+toworld(Vector3.new(xcell-diameter,ycell-diameter,zcell-diameter)))
- if (toworld(cellpos)-pos).magnitude<=radius then
- table.insert(cells,Vector3.new(cellpos.x,cellpos.y,cellpos.z))
- end
- end
- end
- end
- return cells
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement