Page 1 of 1

Gridlocked Civilians

Posted: Wed Aug 14, 2013 3:54 pm
by FatalMarshmallow
In an attempt to create a bunch of gridlocked civilians, I came across this problem. It would appear that neither the player nor the NPC can move in a direction previously moved in by the other. I'm sure the solution is obvious, but I can't see it for the life of me.
Any help is appreciated.
FatalMarshmallow

Re: Gridlocked Civilians

Posted: Wed Aug 14, 2013 5:20 pm
by Robin
Here's your problem:

Code: Select all

function testMap(x, y)
    if map[(civ.grid_y / 32) + y][(civ.grid_x / 32) + x] == 1 then
        return false
    end
	if map[(player.grid_y / 32) + y][(player.grid_x / 32) + x] == 1 then
        return false
    end
    return true
end
This function checks if the player and the NPC can move in that direction. If either can't, neither can. Solution:

Code: Select all

function testMap(obj, x, y)
    if map[obj.grid_y / 32 + y][obj.grid_x / 32 + x] == 1 then
        return false
    end
    return true
end

-- or, better yet:
function testMap(obj, x, y)
    return map[obj.grid_y / 32 + y][obj.grid_x / 32 + x] ~= 1
end
Don't forget to replace calls to testMap with ones that include either player or civ as a first argument, depending on which one you're going to move.

Re: Gridlocked Civilians

Posted: Wed Aug 14, 2013 7:18 pm
by jjmafiae
cant you post in "support & dev" forum instead of the General forum?

Re: Gridlocked Civilians

Posted: Wed Aug 14, 2013 7:30 pm
by FatalMarshmallow
Thanks for the help, I'm an idiot.
Also, my bad for posting in general, will double check in future.