surface.create_entity does not respect collision boxes

Place to get help with not working mods / modding interface.
abregado
Former Staff
Former Staff
Posts: 282
Joined: Sat Aug 30, 2014 9:43 am
Contact:

surface.create_entity does not respect collision boxes

Post 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)
Rseding91
Factorio Staff
Factorio Staff
Posts: 15998
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: surface.create_entity does not respect collision boxes

Post by Rseding91 »

That's by design. If you want collision checks you have to use http://lua-api.factorio.com/latest/LuaS ... ace_entity
If you want to get ahold of me I'm almost always on Discord.
abregado
Former Staff
Former Staff
Posts: 282
Joined: Sat Aug 30, 2014 9:43 am
Contact:

Re: surface.create_entity does not respect collision boxes

Post by abregado »

Wow, thanks! somehow I completely missed that and used count_entities_filtered instead. FIXED!
Post Reply

Return to “Modding help”