Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Objects reacting to the programmatic movement of another one #43

Closed
ggmendez opened this issue Jan 12, 2018 · 8 comments
Closed

Objects reacting to the programmatic movement of another one #43

ggmendez opened this issue Jan 12, 2018 · 8 comments

Comments

@ggmendez
Copy link

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.

@shakiba
Copy link
Collaborator

shakiba commented Jan 15, 2018

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
Copy link
Collaborator

shakiba commented Feb 5, 2018

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?

@quinton-ashley
Copy link

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.

@shakiba
Copy link
Collaborator

shakiba commented Aug 23, 2023

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

@shakiba shakiba closed this as completed Aug 23, 2023
@quinton-ashley
Copy link

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

@shakiba
Copy link
Collaborator

shakiba commented Aug 23, 2023

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

@shakiba shakiba reopened this Aug 23, 2023
@shakiba
Copy link
Collaborator

shakiba commented Aug 24, 2023

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 shakiba closed this as completed Aug 24, 2023
@quinton-ashley
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants