How to check collisions for "teleport" command?
Posted: Mon Jan 09, 2017 9:26 pm
Do you know some easy method to check collisions of entities by using teleport? teleport(position, surface)
www.factorio.com
https://forums.factorio.com/
Code: Select all
-- till parameter is to make sure there is no infinite loop. eg When the player has no other place to reach.
function slapTill(player, till)
if player and player.valid and player.connected then
local randomXdirection = randomPosOrNeg()
local randomX = randomXdirection * math.random(10)
local randomYdirection = randomPosOrNeg()
local randomY = randomYdirection * math.random(10)
local newPosition = {x = player.position.x + randomX, y = player.position.y + randomY}
-- if a wall can be placed at the position, a player won't be stack there. Unless it's an island :)
if player.surface.can_place_entity({name="stone-wall", position=newPosition, direction=nil, force=player.force}) then
local success = player.teleport(newPosition)
if success then
slapReceived(player)
return true
else
return false
end
else
if till > 1 then
return slap(player, till-1)
else
return false
end
end
end
return false
end
I'll look into itorzelek wrote:Silly question:
Why are you checking for stone-wall and teleporting player there?
You should cehck if actual player entity will fit - it has different bounding parameters then wall
(Spoilers: player is an actual entity named player)
There is also a way to find the closest position to something with find_non_colliding_position.darkfrei wrote:Do you know some easy method to check collisions of entities by using teleport? teleport(position, surface)