If you only want your player and enemies to collide with the environment, and "completely ignore" each other, you can simply make the filter function return "slide" for the environment and nil for everyting else in both cases:
Code: Select all
local filter = function(item, other)
if other.isEnvironment then return 'slide' end -- replace '.isEnvironment' by whatever you use
end
Code: Select all
local cols, len = world:move(player, targetX, targetY, filter)
...
local cols, len = world:move(enemy, targetX, targetY, filter)
Another possibility is that you don't want them to completely ignore each other: you want them to "physically pass" through each other, but you want to know about their collision (for example to decrease the player health gradually, or to play a sound). In that case, the filter should return a "slide" collision for the environment, and a "cross" collision for the player/enemies.
Code: Select all
local playerFilter = function(item, other)
if other.isEnvironment then return 'slide' end
if other.isEnemy then return 'cross' end
end
...
local cols, len = world:move(player, targetX, targetY, playerFilter)
...
local enemyFilter = function(item, other)
if other.isEnvironment then return 'slide' end
if other.isPlayer then return 'cross' end
end
...
local cols, len = world:move(enemy, targetX, targetY, enemyFilter)