Sign in to follow this  
draconar

Box2d - options for the mouse joint

Recommended Posts

Hi,
I don't know if here is the correct place to post it, but please move it (moderators) if it is in the wrong topic.

As I can see, many many people are using Box2D as the physics library of choice in their games and some problems and solutions are starting to get "padronized" in a certain way.

therefore I want to ask you guys if any of you know of the options that one can have on how to move an object using the mouse while still interacting with the physical world. I've tried to mouse joint "way", but the object get such an absurd momentum that everything is blow away by it. The effect I want to achieve is that of moving a feather, where it can't move any other object on the screen, but is held by the others, etc.

many thanks!

Share this post


Link to post
Share on other sites
[quote name='draconar' timestamp='1297964870' post='4775486']
The effect I want to achieve is that of moving a feather, where it can't move any other object on the screen, but is held by the others, etc.
[/quote]

I think it is hard to do while keeping the real physics running. Maybe you can try setting your body's mass to 0 (or near) while moving it.
Also, you will probably get more help on [url="http://www.box2d.org/forum/"]the official box2d forum[/url].

Share this post


Link to post
Share on other sites
I use chipmunk physics but the idea is the same. When I grab an object, I reset its forces, set its moment of inertia to INFINITY, and cap its angular speed to 0. It locks the object into place until I'm ready to resume the simulation.

Share this post


Link to post
Share on other sites
[quote name='SriLumpa' timestamp='1297971770' post='4775544']
[quote name='draconar' timestamp='1297964870' post='4775486']
The effect I want to achieve is that of moving a feather, where it can't move any other object on the screen, but is held by the others, etc.
[/quote]

I think it is hard to do while keeping the real physics running. Maybe you can try setting your body's mass to 0 (or near) while moving it.
Also, you will probably get more help on [url="http://www.box2d.org/forum/"]the official box2d forum[/url].
[/quote]
that is the problem. I've posted 3 or more messages on the official forum but I was ignored. Dunno what is going on...


[quote name='Bow_vernon' timestamp='1298003257' post='4775699']
Rather than joint, you might want to 'attach' the body with a spring that gets controlled by mouse, that should do it...
[/quote]

I like this approach very much. I can visualize it but I still dunno how to implement it. There will be a body (mouse joint?) which is a spring, and connected to that spring will be the body I wan't to move, correct? I'm just not seeing how I will attach the spring to the mouse, but, yes, this is the effect I want to achieve.

cheers!

Share this post


Link to post
Share on other sites
[quote name='draconar' timestamp='1298132196' post='4776335']
I like this approach very much. I can visualize it but I still dunno how to implement it. There will be a body (mouse joint?) which is a spring, and connected to that spring will be the body I wan't to move, correct? I'm just not seeing how I will attach the spring to the mouse, but, yes, this is the effect I want to achieve.
[/quote]

Actually I'd say that the mouse joint does something very much like that spring thing already, so I'm not sure you would gain much.
Also, my suggestion of setting the moving body's mass to 0 is probably not working, if the force from the joint can transfer to other bodies in contact.

Another idea is to set every other body to static when you want to drag, and then reset their original properties when you resume the simulation.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this