Making a body move over another?

Hi,

Any ideas how you would make a body move over the top of another without dragging the other with it? lets say you have a square, and it's moving over a trangle shape, right now I'm using

Code:
SetLinearVelocity(new b2Vec2(2, 0));


but it just takes the triangle shape with it, do I just have to "fix" the triangle in place somehow, maybe with setting the mass to 0? but what if I wanted another object to hit the triangle and be able to move it, is it a case of detecting which objects hit? and then once you know what object has hit, give the triangle it's original mass back so it's moved correctly??

thanks for any advice.
What do you mean by move over the top?
Redshift wrote:
What do you mean by move over the top?


slide over, so the square would move/slide up the triangle like it was moving up a "ramp" so to speak. I know making the triangle (ramp) would stop it from moving but I then want that same object to be able to be moved by other bodies in the world. So basically what I need is for the triangle to react differently in the physics world environment depending on what's collided with it.
This sounds like a more complex simulation than a simple rigid body one, in that case then yes, you'd probably want to change how they behave based on a contact result. There was a forum post about making a conveyor belt that had a couple ideas on how to do that. Setting the mass 'should' work, as long as you set the inertial tensor as well( just call setmassfromshapes(), easiest way), or you could try a joint to hold it in place( a distance joint with length zero? attached to the ground body of the world? ) Just delete the joint when it gets hit by anything other than the box.
VengantMjolnir wrote:
This sounds like a more complex simulation than a simple rigid body one, in that case then yes, you'd probably want to change how they behave based on a contact result. There was a forum post about making a conveyor belt that had a couple ideas on how to do that. Setting the mass 'should' work, as long as you set the inertial tensor as well( just call setmassfromshapes(), easiest way), or you could try a joint to hold it in place( a distance joint with length zero? attached to the ground body of the world? ) Just delete the joint when it gets hit by anything other than the box.


Something I'm a but unclear on is the order of which events happen. So it's possible to get an alert from a listener that 2 bodies have collided before any of them are actually moved as a reaction to that collision?
Yes, sort of, but not really. What you really want to do is not change the ramp, but the player. Best case scenario is to have the player not collide with the physics world automatically, but only move manually, and only affect other objects manually. This is probably more complicated than you're looking for.

Here's a couple hacks that might work:

1) Make the ramp static whenever it comes to a stop and whenever hit hard enough, move it manually.
2) Give the ramp a very large amount of mass and high frictional coefficient. When it collides with something, adjust the force to something more realistic.
Hangar wrote:
Yes, sort of, but not really. What you really want to do is not change the ramp, but the player. Best case scenario is to have the player not collide with the physics world automatically, but only move manually, and only affect other objects manually. This is probably more complicated than you're looking for.

Here's a couple hacks that might work:

1) Make the ramp static whenever it comes to a stop and whenever hit hard enough, move it manually.
2) Give the ramp a very large amount of mass and high frictional coefficient. When it collides with something, adjust the force to something more realistic.


Thanks for the info, a few questions.

1) So if I move things manually (which I'm not sure how to do btw, setXForm ?) will they still bounce off each other correctly etc when they do collide?

2) When you say very large amount of mass, im not sure what numbers you are talking about. With other values the scope is usually 0 to 1, but with the mass or density there doesn't seem to be a scope so im never too sure (apart from trial and error) how high you can go with the values, like for example, what amount of mass value would basically make something immovable?
1) Er, just apply forces/impulses or set velocity manually. Using SetXForm, b2Shape::Refilter, adding/removing shapes and changing mass may cause some skipped collisions or other oddities, but velocities are relatively safe to tinker with.

What I meant is to switch from a static to dynamic body and apply the force manually. Setting the mass (to switch between static/dynamic) doesn't have too much impact. However, you'll have to do it outside the timestep.

2) 1.0 mass is 1 kg. I don't know the right number to use. I might play with 100 kg and 1000 kg and see if I should go higher or lower. Note that it won't be completely immovable.


Thinking about it some more, you just want the player and possibly other bodies to be able to climb the slope, right? Perhaps all your bodies' masses are too low. A character might weigh about 100 kg. The slope might be 10 times that.

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