Keep object attached to the ground

Hi,

I've got a random created landscape which is made up of box2d bodies, now, when my player (box2d object) goes over this landscape, I want it to follow it, i.e. not go off the ground, how would this be done - would I need some type of joint?

Regards,
Steve
I'm not really sure what you're asking there Steve - do you mean, that you're getting a problem where your player object goes into the air as it tries to move over terrain? Or when it goes down terrain it 'floats.' If that's the case then that's a byproduct of the engine - a fix would be to make your player object very dense, which would give gravity a greater effect on it and hence it would drop faster.

The big problem that you'll have with making a joint to the ground is that if you have your landscape made up of lots of different objects then you'd need to create and destroy that joint as you pass over a new object, not impossible but could be costly on efficiency.

SC.
Hi,

The object moves correctly when going over the terrain, was just wondering if it was possible to 'fix/glue' the object to the landscape (like in line surfer, but I doubt that uses box2d) or even when object does go in the air, stop it from going too high.

Thanks,
Steve
I was just reading over this example of a slicing engine, and ray tracing to detect poly edges.
http://www.emanueleferonato.com/2011/06 ... ith-box2d/

Perhaps you could use a similar system to find the closest poly marked as ground (userdata, or add a ground bool to box2d yourself).
I.e. trace maybe 5 times at varying angles to find the closest point to the ground.. and shove the object in that direction, or move
it manually if you know the size of the object and the ground shape allows for it, etc. (i.e. round body, no ground above the body).

Pretty late response, but I hope it helps,
J

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