Move bodies with your hand - box2d

Hi guys, some days ago after viewing the video from vux about his bar table application where he moved the circle bodies with his hand i decided to try and replicate that effect…

I got to a decent point but there is something that is really not working and i think is due to the movemousejoint node…

In very simple words this is what i do:

  • I find the bodies that are in contact with the “interactive bounds” via aabbquery node
  • i create a mousejoint on those bodies
  • here is the trickiest part in my opinion - i should move this bodies along with the “interactive bounds” that simulate the hands captured via contour node. i’ve done it (as you can see from the patch) but it’s very buggy in particular when more bodies are attached to the same interactive bound…there is some sort of flickering of the joints that could be due to the fact that the order of the slices of the contour x and y coordinates are always changing…
  • i’m always checking for bodies that detach from the “interactive bounds”, if this happens the joint is deleted

by the way i’ve attached the patch i’ve been working on and it’s well (i think) commented, so it won’t be hard to understand whay i’ve done and i hope that some of you can find what i’m missing out in the process…

Just open the patch and click on the create body, after some seconds the problem will be clear, and in the case it isn’t, just click create body a second time :)

Any help/tip/suggestion to make the patch better and/or to solve the problem is higly appreciated
thanks vvvvery much

thx to vux for his tips… oh he told me that maybe using the custom node to store additional data on the joints could help me, but i have never understood how, maybe this tip could be of some help to you!! thx to kalle too for helping me out with his amazing exclude (spreads) subpatch! (11.7 kB)


mouse joint is the seasiest way to maintain that. What i also normally do is make sure that the current object can only have one mouse joints at the same time.

Easy way is to store the contour id in the custom pin.

hi vux or anyone else who want to follow this thread
i’ve understood what you said about storing the contour id in the custom pin of the mousejoint but can’t really go somewhere with that…
i’m feeling a bit stupid but i’m stuck in the same point as before…in my version of the patch i am already checking if the body already has a joint before creating a new one:

  • i pass to the createmousejoint all the bodies and positions that are the result of the aabbquery and then i set the Do Create pin to a spread of either 1 or 0 --> With getjointdetails i get the ids of the bodies that have a mousejoint and with sift i can get which of the bodies that are in the aabbquery have a joint, i do the opposite of the hint pin and i use that to trigger te Do create pin… in this way (in my opinion) i’m assuring that a joint is created only to those bodies that are in the aabbquery and that does not already have a joint
  • to destroy the joint when the body is away from the “interactive bounds” i do this: i get all the bodies that have a joint and are not in the aabbquery, i select the corresponding joints via getslice that goes to the destrojoint node…so in this way everytime that a body goes away from the interactive bound its joint is destroied…

so is this method buggy? if yes, i can’t understand why!??!

i also tried to do something by storing the contour id in the custom pin of the mousejoint in this way:

  • everytime i create a joint i give him the custom name of the corresponding contour id that came in contact with that body, to check whether i have to set the Docreate pin of the createmousejoint node to 1 i follow this method --> i get the ids of the bodies that have a joint and i select those that have the custom pin set to one of the contour ids (with sift and select node) and at this point with sift i see which of the bodies id are in the aabbquery and have a joint whose custom pin is set to one of the contour ids, and now as in the previous method i invert the result of the hint pin of the sift node and use that to trigger the DoCreate node…

both of these methods go crazy when more bodies are in contact with the interactive bounds as you can see from the patch i uploaded in the first post…

am i doing wrong something in the theory or i’m applying the right things in the wrong way??
please help it’s becoming a challenge between me and v4!!!