Page 1 of 1

surface.create_entity does not respect collision boxes

Posted: Thu Feb 16, 2017 2:08 am
by abregado
Discovered this while messing with autoplace controls. Increasing the size of a resources Collision Box causes the autoplace controls to nicely space out the resource tiles. After trying this with a custom script to spawn objects in a field I discovered that Surface.create_entity does not respect collision boxes.

Could there be an option in create_entity to force placement or respect collision?

I used this code in my control.lua to demonstrate the issue

Code: Select all

script.on_event(defines.events.on_chunk_generated, function(event)
  local boundingBox = event.area
  local surface = event.surface
  local pos1 = boundingBox.left_top
  local pos2 = {boundingBox.left_top.x+1,boundingBox.left_top.y+1}
  local pos3 = {boundingBox.left_top.x+2,boundingBox.left_top.y+2}
  local ent1 = surface.create_entity({
		name="assembling-machine-1",
		position=pos1,
		force='player'
		})
	surface.create_entity({
		name="assembling-machine-1",
		position=pos2,
		force='player'
		})
	surface.create_entity({
		name="iron-ore",
		position=pos3,
		})
end)

Re: surface.create_entity does not respect collision boxes

Posted: Thu Feb 16, 2017 2:21 am
by Rseding91
That's by design. If you want collision checks you have to use http://lua-api.factorio.com/latest/LuaS ... ace_entity

Re: surface.create_entity does not respect collision boxes

Posted: Thu Feb 16, 2017 11:19 am
by abregado
Wow, thanks! somehow I completely missed that and used count_entities_filtered instead. FIXED!