# Making the player walk on walls in box2d

I'm making a game in stencil where players walk form left to right along randomly generated walls. I cant use waypoints, since the walls' shapes and positions are unpredictable.

Here's a descriptive sketch:

The red line is the player's path. The red circles are what I thought might make good waypoints until I scrapped the idea.

-
I embedded the sketch and made some corrections and clarifications. Did I get them right? – Anko Mar 20 '13 at 21:15
What is your question? – Trevor Powell Mar 20 '13 at 21:19
I'm really lost in how to implement something like this,rotating and changing forces only work to climb walls,changing gravity affects all characters on scene,i need a kind of pathfinding to make the character stick to the walls. – MetalLord Mar 20 '13 at 21:45

Depending on what you actually wish to do , either 1) Change the gravitation upon colision with a wall, so it faces "into" the wall.

2) Add high friction for walls, equal 1 to the body fixture. It allows sticking to walls.

-

You can make a raycast from your character into all all four directions. If you only hit the ground then you don't have to do anything. If you hit a wall or the ceiling you add a weld joint to your character and the wall. You destroy and recreate the joint inside your update loop, so the character can move, but is tied to the wall/ceiling and doesn't fall down. There are still two tricky parts left.

1. Corners: When you come to a corner (two ray casts hit a wall) you must switch the wall on which you create the joint, depending on the direction you are walking to.
2. Walking direction: When you walk around a corner, you must track the direction you are walking to, so you can press forward all the time and follow the shape of the wall.
-
Most of that is unnecessary. Easiest solution change the gravity vector. – Vallentin Oct 23 '13 at 15:58
Which will change the gravity for every body, not only the player. Since the OP didn't specify, I cautiously made the assumption. – zilluss Oct 24 '13 at 6:19
Then it's still the easiest way, because if the OP want the world to "keep" its original gravity, then simple use 2 gravity vectors, one for the player and one for everything else. – Vallentin Oct 24 '13 at 6:54
You mean a force on the player that's applied in every update? Hadn't thought of that, but sounds like a much better idea. – zilluss Oct 26 '13 at 9:08