Ball random move !?

I need some ideas for those three spheres in middle to move randomly through labyrinth. Labyrinth ground and walls are rigid bodies and i`m moving white ball using .applyForce(using keyboard)…if that helps

I had to solve that problem for Zombie Pac-Man:

https://playcanvas.com/project/331628/overview/zombie-pacman

What I ended up doing was as follows. I define the game level as a two-dimensional array:

var mapDfn = [
    [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ],
    [ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ],
    [ 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1 ],
    [ 1, 9, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 9, 1 ],
    [ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ],
    [ 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1 ],
    [ 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 ],
    [ 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1 ],
    [ 1, 3, 1, 3, 1, 0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 0, 1, 3, 1, 3, 1 ],
    [ 1, 1, 1, 1, 1, 0, 1, 2, 1, 1, 1, 4, 1, 1, 1, 2, 1, 0, 1, 1, 1, 1, 1 ],
    [ 8, 2, 2, 2, 2, 0, 2, 2, 1, 6, 2, 5, 2, 7, 1, 2, 2, 0, 2, 2, 2, 2, 8 ],
    [ 1, 1, 1, 1, 1, 0, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 0, 1, 1, 1, 1, 1 ],
    [ 1, 3, 1, 3, 1, 0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 0, 1, 3, 1, 3, 1 ],
    [ 1, 1, 1, 1, 1, 0, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 0, 1, 1, 1, 1, 1 ],
    [ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ],
    [ 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1 ],
    [ 1, 9, 0, 0, 1, 0, 0, 0, 0, 0, 0,10, 0, 0, 0, 0, 0, 0, 1, 0, 0, 9, 1 ],
    [ 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1 ],
    [ 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 ],
    [ 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1 ],
    [ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ],
    [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
];

This creates the standard Pac-Man map. Each number determines what the map square should be: blank, wall, power pellet, zombie, etc. So player and NPCs can go anywhere that is not a wall.

So to allow the NPCs to roam around the level, I do something very, very simple. I simply select a square that is not a wall tile at random and I instruct the NPC to go there. To determine the path of the NPC to the target square, I used a library called pathfinding.js. Check it out:

The function that creates the path is ‘getPath’ in map.js:

https://playcanvas.com/editor/code/331628/map.js