planck.js icon indicating copy to clipboard operation
planck.js copied to clipboard

Objects reacting to the programmatic movement of another one

Open ggmendez opened this issue 7 years ago • 3 comments

I need the objects of my world to react as another 'special' object passes by and touches them. For technical reasons, I am setting the position of this special object programmatically (setting the theBody.c_position.c.x and theBody.c_position.c.y properties).

Suppose I position the special object obj at a certain point (x,y) around which there other objects. obj is located properly (I can see it moving) but it does not seem to affect the surrounding objects when touching them. Instead, it just overlaps them and is just drawn on top of them.

What am I missing here? I suspect the problem has to do with motion, but the only thing I have at hand is the desired location of the object I need to move programmatically.

ggmendez avatar Jan 12 '18 00:01 ggmendez

I guess I don't know the answer! However I recommend to first search if it is possible with Box2D, and if it is then share a sample here so that I can have look.

shakiba avatar Jan 15 '18 08:01 shakiba

I just revisited this issue and read it more carefully, I think it should not be difficult to fix. If you have not solved this issue yet, can you please share a sample l can test?

shakiba avatar Feb 05 '18 01:02 shakiba

I have noticed this to, it's still an issue. You can workaround it by setting the velocity instead of position but it shouldn't be necessary imo.

quinton-ashley avatar May 20 '22 22:05 quinton-ashley

I guess the main issue here is updating c_position.c, you would need to use Body.setPosition() or Body.setTransform().

shakiba avatar Aug 23 '23 07:08 shakiba

Well that doesn't work either cause I use body.setPosition. I just call it "teleporting" check out the second example: https://p5play.org/learn/sprite.html?page=2

quinton-ashley avatar Aug 23 '23 14:08 quinton-ashley

The first teleport actually works fine in the link. I will make an example to see how things are.

shakiba avatar Aug 23 '23 19:08 shakiba

Here is a working demo: https://piqnt.com/space/1ICyExOEW

The only caveat was that you need to awake at least one of the bodies after setPosition(). I update the code to do that automatically on setTransform/setPosition/setAngle

shakiba avatar Aug 24 '23 05:08 shakiba

@shakiba wow this is a small fix that opens up a huge range of opportunities for use in games. Thank you!

quinton-ashley avatar Aug 24 '23 16:08 quinton-ashley