Find colliding entities
Posted: Thu Jun 01, 2017 4:36 pm
I need to get a list of all entities that would collide with a newly-created entity (in order to deconstruct them before placing a new one).
I also need to filter the resulting list to exclude things such as ghost entities or entities marked for deconstruction,.
Right now, I use find_entities_filtered with the area set to the collision box of the yet-to-create entity, centered around its position.
But this doesn't work on 45°rails because their bounding box has an orientation which is ignored by find_entities_filtered.
The best way to do this would be to have a dedicated function:
LuaSurface::find_colliding_entities{name = ..., position = ..., direction = ...}
Returns a list of entities that would collide when placing this entity
Another alternative would be to support the undocumented BoundingBox::orientation property in find_entities/find_entities_filtered although that requires a bit more work (since you have to actually compute the bounding box from the prototype's collision box: center it, rotate it)
I also need to filter the resulting list to exclude things such as ghost entities or entities marked for deconstruction,.
Right now, I use find_entities_filtered with the area set to the collision box of the yet-to-create entity, centered around its position.
But this doesn't work on 45°rails because their bounding box has an orientation which is ignored by find_entities_filtered.
The best way to do this would be to have a dedicated function:
LuaSurface::find_colliding_entities{name = ..., position = ..., direction = ...}
Returns a list of entities that would collide when placing this entity
Another alternative would be to support the undocumented BoundingBox::orientation property in find_entities/find_entities_filtered although that requires a bit more work (since you have to actually compute the bounding box from the prototype's collision box: center it, rotate it)