Checking Collision and Movement

I’ve tried to figure this one out myself and no luck, so I’ll give it a shot here.

In it’s most simple form I have a tile based game where the character’s movement is tied to the grid(example: he can only move 16 pixels in one direction and can’t move again till he has moved that distance). I have walls. All objects are 16x16. Since the walls are 16x16 and so is the character, if they are adjacent they will share a border which will cause collision.

To remedy the situation, I tried changing the walls to isSensor in order to allow that shared border. I didn’t want to resize artwork because that collision is necessary. If that collision happens, I disable the character from moving in that direction. It works great when moving one tile at a time.

The Problem: If the user holds down a button on the D-Pad, the characters movement will be fluid. It’s down by adding a indicator on buttonDown/buttonUp. If my transitionTo completes and buttonHeld is true, it will start another transitionTo in that direction. This causes a problem. Since the wall is a sensor I lose preCollision. My events fire in this order:
transition.to()
completeTransitionCall()
onCollision()

In that onCollision call I say to disable movement, but since it’s firing after the completion, I cant’ set the flag that says don’t move in time. Here is a code example for moving left.

[code]local onButtonLeftEvent = function(event)
if event.phase == “press” then

if(player.isMoving == false and openDirection.openLeft) then
player.direction = DIRECTION_LEFT
player.state = STATE_WALK_LEFT
trans = transition.to(player, {time=PLAYER_SPEED, x=player.x-16, y=player.y, onStart=StartTransition, onComplete=CompleteLeft})
buttonHeld = true
player.isMoving = true
end
else
buttonHeld = false
end
player:prepare(“anim” … player.state)
player:play()
end

CompleteLeft = function(obj)
print(“CompleteLeft”)
if(buttonHeld and openDirection.openLeft) then
trans = transition.to(player, {time=PLAYER_SPEED, x=player.x-16, onStart=StartTransition, y=player.y, onComplete=CompleteLeft})
player.isMoving =true
else
player.isMoving = false
player.state = STATE_IDLE_LEFT
player:prepare(“anim” … player.state)
player:play()
end
end

local function onCollision ( event )
local object1 = event.object1
local object2 = event.object2

if(math.round(object2.x-object1.x) == 24 and player.state ~= STATE_WALK_RIGHT) then
openDirection.openLeft = false
elseif(math.round(object1.x - object2.x) == 24 and player.state ~= STATE_WALK_LEFT) then
openDirection.openRight = false
elseif(math.round(object2.y-object1.y) == 24 and player.state ~= STATE_WALK_DOWN) then
openDirection.openUp = false
elseif(math.round(object1.y - object2.y) == 24 and player.state ~= STATE_WALK_UP) then
openDirection.openDown = false
end
end
[/code]

I’m converting this game from Flash(didn’t like using AIR at all). Over there I could pass in some location parameters and see if my object would collide with anything if my object was in that location. Is it possible to detect if something will collide with an object in it’s transition? Is there any other ways to do this. I’ve been banging my head on this for a week. I set the player to isBullet as well to force the update on the collision. The collision is always hitting at the exact right time. Sorry for the wall of text!

EDIT: I fail at English! [import]uid: 114566 topic_id: 21367 reply_id: 321367[/import]