This project has moved and is read-only. For the latest updates, please go here.

Mouse Spring/Joint ?

Topics: Developer Forum, Project Management Forum, User Forum
Oct 28, 2009 at 11:23 AM

I can't seem to make a mouse joint, basicly im trying to make a joint that lets an object follow the mouse without any lag or delay while still working with the physics (But looking like the bodys position is just being changed)

Anyone got any ideas?

Nov 10, 2009 at 8:42 AM

What happens if whatever you're holding is run into a static object? Does it get pulled through with the mouse? Does the mouse let go? Is the mouse prevented from traveling further?

Nov 10, 2009 at 10:24 AM

Well it would just run into the static object... and not be able to pass though.

I will also write my own code however to prevent the mouse from traveling any further. So this way i can just drag around objects with no delay or springiness but still have them in the physics sim.
Imagine the mouse spring from the farseer samples but with no lag between moving the mouse and the object following, i belive there are quite a few people who have wanted/tried to get this.

Any ideas?

Nov 10, 2009 at 1:12 PM

If I understand you correctly, perhaps you could create a Slider Joint with one end tracking the position of the mouse, and the other end attached to the body you want to track.

Another approach may be to create a Linear Spring between the target body and a body tracking the Mouse position - (Spring RestLength set to the distance between the mouse and target body when the mouse is first pressed) You can tune the Springs DampningConstant & SpringConstant to create a very 'stiff' spring ?

Nov 10, 2009 at 1:31 PM
Edited Nov 10, 2009 at 1:32 PM

I have tried the 2nd approch you suggested but it is very hard to control and stuff and doesnt work that well.

However i have never used a slider joint, i will give that ago tommrow...
Thanks for the help.

Nov 11, 2009 at 8:12 AM

Another idea is to add a body to the engine and manually set it's position to the moue's every update, then add a weld joint between that and the selected item.

Nov 11, 2009 at 6:36 PM
Edited Nov 11, 2009 at 6:40 PM

Ha! Good idea RogueCommander, the Weld Joint works nicely. I didn't play with it before because it's not described in the manual.

dan, try using the WeldJoint - be sure to give the mouse body a very large mass (I used float.MaxValue), and set the anchor to the common World Point you want to bind them at. This will lock the orientation of your bodies while they are being controlled by the mouse, you could use a different type of joint if this is not desired.

Nov 12, 2009 at 12:13 AM

Im currently using a revolute joint but perhaps a weld would work better so ill give it a try.