Floating/Flying and Movement

Hi! Awesome engine and forums. 🙂

I have a little question about character movement. I'm trying to make a character that moves left/right across a surface while floating above it. The ways I've thought about doing this are:

1) using a sensor box to detect ground; if there is ground add some upwards force

2) cast a ray down from the player to figure out what the distance from the ground and what force to adjust by (Box2D doesn't appear to have this ability though?)

3) use a mouse joint to try to pin the player to a goal point; when moving left change the goal point

I've tired 1 and 3 so far, and they don't seem to work very well.

I'm curious if anyone has tried this or if there are other (better) methods?

Thanks! 🙂
Strangely, I actually did this exact thing today.
I used no. 2
Box2D does have a ray function but I couldn't get it to work, so I made my own one using the line intersection method from here:
http://ozviz.wasp.uwa.edu.au/~pbourke/geometry/lineline2d/
cmann wrote:
Strangely, I actually did this exact thing today.
I used no. 2
Box2D does have a ray function but I couldn't get it to work, so I made my own one using the line intersection method from here:
http://ozviz.wasp.uwa.edu.au/~pbourke/geometry/lineline2d/


That's interesting, I didn't realize there was a ray function in Box2D. Is it the TestSegment/b2Segment stuff that you're referring to?
Yes, but I have no clue how it works.
I have been trying out method No.2 using TestSegment/ApplyForce and it is working out pretty well. The biggest problem is that since the character doesn't actually collide with the world to walk on it, you have to do all those things that Box2D would normally do for you, ie:
-friction
-transfer the weight/impact of the character to what he is standing on
-slide down slopes
-move the character when what he is standing on moves
It's not exactly a piece of cake, but I'm pleased with what I have so far:
http://www.youtube.com/watch?v=LijiW5HOUZM
That is really good, irresistible force. I wonder though if it would work as well with shorter rays, or allowing rotation. Also, aren't friction and "move the character when what he is standing on moves" the same thing, just dynamic and static friction.
It works fine with shorter rays, to make the character crouch I just set the 'leg length' to a shorter distance. Allowing too much rotation would make things a bit messy though - as it is now, the torso will correct any rotation within a very short time, like less than half a second. It did occur to me that making it less able to correct itself could allow for the character to be tripped/knocked over by things, but I didn't want to have that as part of the game from a playability point of view, because it would probably get quite annoying. Later when it comes to swimming I will need to allow the body to rotate, but I haven't thought much about how I'll do that yet.

Yeah you are right about "move the character when what he is standing on moves" being just friction.
irresistible force wrote:
It works fine with shorter rays, to make the character crouch I just set the 'leg length' to a shorter distance. Allowing too much rotation would make things a bit messy though - as it is now, the torso will correct any rotation within a very short time, like less than half a second. It did occur to me that making it less able to correct itself could allow for the character to be tripped/knocked over by things, but I didn't want to have that as part of the game from a playability point of view, because it would probably get quite annoying. Later when it comes to swimming I will need to allow the body to rotate, but I haven't thought much about how I'll do that yet.


Out of curiosity, how are you correcting the rotation? Applying torque?
Yes, enough torque to correct the rotation within a very short time. In my opininon this looks more natural, since body at least rotates a tiny bit when it hits things, instead of having a perfectly non-rotating 'man of steel'.
Yeah, that definitely sounds like it would look/feel better.

How do you set up the segment tests btw? I can't seem to find any documentation on it...

Original thread: https://box2d.org/forum/viewtopic.php?t=1053