Help in random movement

Hello, i have a problem making the enemy in my game walking in random directions, its a 2D game with the vision of Bomberman, the enemy walks but he stop after some collisions, i need the help of you guys.

Thanks
[import]uid: 124611 topic_id: 25734 reply_id: 325734[/import]

Once the characters velocity = 0, pick a random number between 1 and 4 for north, east, south and west, then set the characters velocity in the new direction.
[import]uid: 67933 topic_id: 25734 reply_id: 104059[/import]

I made that but we stops walking after he colide sometimes, he colide and stop, he don’t choise another direction. [import]uid: 124611 topic_id: 25734 reply_id: 104331[/import]

OK, well without seeing your code it will not be possible to find out why this is happening. Do you get any errors? Are you printing anything to the terminal, (such as collisions, or the characters velocity)?

Can you post the code that’s giving you the problem and we’ll take a look?

Dan [import]uid: 67933 topic_id: 25734 reply_id: 104357[/import]

Thats the point i don’t get an error, here is a piece of the code.

function onLocalCollisionMacaco( self, event )
–numberChoiceOne = math.random(1,4)
macaco.moved = true
–macaco.move_direction = “nulo”
if(event.phase == “began”) then
–[[if(event.other.tag == LevelHelper_TAG.BLOCOS_D) then

if(numberChoiceOne == 1) then
if(macaco.move_direction ~= “down”) then
macaco.MoveDown = true
macaco.move_direction = “down”
end
end
if(numberChoiceOne == 2) then
if(macaco.move_direction ~= “up”) then
macaco.MoveUp = true
macaco.move_direction = “up”
end
end
if(numberChoiceOne == 3) then
if(macaco.move_direction ~= “right”) then
macaco.MoveRight = true
macaco.move_direction = “right”
end
end
if(numberChoiceOne == 4) then
if(macaco.move_direction ~= “left”) then
macaco.MoveLeft = true
macaco.move_direction = “left”
end
end
end–]]

if(event.other.tag == LevelHelper_TAG.BLOCOS_I) then

if(numberChoiceOne == 1 and macaco.move_direction ~= “down”) then
macaco.MoveDown = true
macaco.move_direction = “down”
print(“down”)
end
if(numberChoiceOne == 2 and macaco.move_direction ~= “up”) then
macaco.MoveUp = true
macaco.move_direction = “up”
print(“up”)
end
if(numberChoiceOne == 3 and macaco.move_direction ~= “right”) then
macaco.MoveRight = true
macaco.move_direction = “right”
print(“right”)
end
if(numberChoiceOne == 4 and macaco.move_direction ~= “left”) then
macaco.MoveLeft = true
macaco.move_direction = “left”
print(“left”)
end
end
end
end
macaco.enemy_macaco.collision = onLocalCollisionMacaco
macaco.enemy_macaco:addEventListener ( “collision”, macaco.enemy_macaco )

The macaco.enemy_macaco is my enemy and i change his direction aftter he collides,but i do that in the update:

numberChoiceOne = math.random(1,4)
if(macaco.moved == false) then
enemy_direction = “down”
macaco.movementDown()
end
if(macaco.MoveDown == true) then
macaco.movementDown()
end
if(macaco.MoveUp == true) then
macaco.movementUp()
end
if(macaco.MoveRight == true) then
macaco.movementRight()
end
if(macaco.MoveLeft == true) then
macaco.movementLeft()
end
[import]uid: 124611 topic_id: 25734 reply_id: 104419[/import]