Ways to block a moving object?

Hello, I will try to keep it short and quick:

I’m trying to block a moving object that moves with velocity with a wall or something similar.

Now, if I use physics to block it with a wall (perhaps a display.newLine), with dynamic bodies colliding it will glitch the object to a certain position. To avoid that I could use static bodies instead right? However, velocity doesn’t work with static bodies. So I thought I could make the wall to be dynamic and my object to be kinetic, but again, through collision I believe the wall will get glitched in some unwanted position.

I then thought about limiting the velocity through a runtime listener checking for the objects position, it works, but through the velocity the object tends to cross the limit before the listener reacts to the object’s position.

Any hints that could help me?

If I find a solution by then I will make sure to update this thread for the others,

Cheers,

Phil

Did you try making the wall static and the moving object dynamic? If the wall is static then it shouldn’t be compelled to move by any force. If you need to move the wall, I think you could just use transition.to().

Hi @philippe.roubert,

As @hasty says, you should consider making the wall(s) “static” and the other objects “dynamic”. I assume the walls won’t need to move at any point. Also, I suggest that you make the walls a “newRect()” object, not a “newLine()” object. There are some quirks with line objects that are made into physical bodies, and generally I avoid using them in that way. Also, a “line” is generally thin, and if you have a very thin line, and a fast-moving object, there’s a possibility that the moving object will fly through the line without detecting a collison because it move in time-step from one side of the line to the other… yes, this is uncommon, but it’s better to just avoid the possibility by using a thicker rectangle object.

Best regards,

Brent

 
Hi, thanks for your answer, that’s what I thought on doing, thought it would be rather a bad choice considering the collisions effect in which the bodies get to be glitchy through the velocity, now how you said, I could have used transitions which would have made it really easier, but I’m making the object move through the user’s interaction, other said with the accelerometer and the setLinearVelocity, which makes it impossible to use transitions, however fortunately I fixed it, here’s how:
 
-The walls should have a static body with the bounce and friction properties set to 0
 
-The moving object should have a dynamic body, with the bounce and friction properties set to 0, adding to this I changed the isFixedRotation value to true (and I believe this was the thing causing trouble)
 
It almost runs flawlessly, but it got my problem fixed, so I’m going to close the thread.
If you have questions about it, feel free to message me :slight_smile:
 

Thanks Brent Sorrentino for the answer, yes, that’s a point to not forget: rather use a rectangle more than a line.

Did you try making the wall static and the moving object dynamic? If the wall is static then it shouldn’t be compelled to move by any force. If you need to move the wall, I think you could just use transition.to().

Hi @philippe.roubert,

As @hasty says, you should consider making the wall(s) “static” and the other objects “dynamic”. I assume the walls won’t need to move at any point. Also, I suggest that you make the walls a “newRect()” object, not a “newLine()” object. There are some quirks with line objects that are made into physical bodies, and generally I avoid using them in that way. Also, a “line” is generally thin, and if you have a very thin line, and a fast-moving object, there’s a possibility that the moving object will fly through the line without detecting a collison because it move in time-step from one side of the line to the other… yes, this is uncommon, but it’s better to just avoid the possibility by using a thicker rectangle object.

Best regards,

Brent

 
Hi, thanks for your answer, that’s what I thought on doing, thought it would be rather a bad choice considering the collisions effect in which the bodies get to be glitchy through the velocity, now how you said, I could have used transitions which would have made it really easier, but I’m making the object move through the user’s interaction, other said with the accelerometer and the setLinearVelocity, which makes it impossible to use transitions, however fortunately I fixed it, here’s how:
 
-The walls should have a static body with the bounce and friction properties set to 0
 
-The moving object should have a dynamic body, with the bounce and friction properties set to 0, adding to this I changed the isFixedRotation value to true (and I believe this was the thing causing trouble)
 
It almost runs flawlessly, but it got my problem fixed, so I’m going to close the thread.
If you have questions about it, feel free to message me :slight_smile:
 

Thanks Brent Sorrentino for the answer, yes, that’s a point to not forget: rather use a rectangle more than a line.