Using a kinetic body instead of a MouseJoint?

  ... the Physics Box2D Extension for AndEngine.

Using a kinetic body instead of a MouseJoint?

Postby brash » Thu Jan 20, 2011 11:54 pm

I am new to Box2D (and game programming), and I think I am not understanding something fundamental. The Box2D documentation mentions that MouseJoints are not suited for game programming and that one should probably use a kinetic body instead:

Many users have tried to adapt the mouse joint for game play. Users often want to achieve precise positioning and instantaneous response. The mouse joint doesn’t work very well in that context. You may wish to consider using kinematic bodies instead.


I think I understand how to use a MouseJoint and I think I understand what a kinetic body is. But I don't understand how the two are interchangeable. Could someone explain?

To give a bigger picture: I would like to cause a sprite to bounce off my finger if I drag my finger into it. MouseJoints looked like what I wanted, until I read the Box2D documentation.

Any help would be greatly appreciated!
brash
 
Posts: 357
Joined: Thu Jan 20, 2011 11:44 pm

Re: Using a kinetic body instead of a MouseJoint?

Postby D13 » Fri Jan 21, 2011 5:01 pm

I poked around doing something similar a while back just doing some Box2D testing. What I did was create a static body to control. I moved the static body around the screen using setTransform and any dynamic bodies were knocked out of the way or otherwise contacted the static body in the process. Using a Kinetic body probably would work just as well. Both static and kinetic bodies act as they have infinite mass, meaning they do not respond to collision forces, and their commanded movements will not be interfered with by other objects.

How does that compare with a mouse joint? Well, with a mouse joint you are not positioning a body to be in a specific location. You are causing forces to be applied to a dynamic body to move towards a specified location. Whether or not it actually gets to that location depends on the objects in the way, and any interactions it has that cause it's orientation to change.

Have a look at the Box2D testbed on the Box2D google code site. Most of the examples use mouse joints to move stuff around. You will get an excellent idea of what mouse joints do, but how they sometimes cannot move objects to the selected locations (they cannot make dynamic bodies pass through other static bodies for instance).
D13
 
Posts: 172
Joined: Wed Oct 06, 2010 6:08 am
Location: Toronto, Canada

Re: Using a kinetic body instead of a MouseJoint?

Postby brash » Fri Jan 21, 2011 6:05 pm

Ok, the mouse joint stuff makes sense to me. I'm still confused about using setTransform to do what I want.

I tried something like this to begin with when I was first messing around with Box2D, but the object I moved into would not "bounce," it just moved out of the way. From my understanding, this is because when you setTransform, the body you transform doesn't have any velocity.

I can setLinearVelocity as well, based on the last coordinates of the touch event, but obviously I don't want the object to have any velocity if it is at the same point as my finger (i.e. after it is transformed).

Am I think about this the wrong way?
brash
 
Posts: 357
Joined: Thu Jan 20, 2011 11:44 pm

Re: Using a kinetic body instead of a MouseJoint?

Postby brash » Sat Jan 22, 2011 12:23 am

Ok, I think a much easier way to do this is going to be to track the velocity of my finger and then just applyForce to the sprite I want to hit. Only, I'm not sure what the force values should be... I started a new thread for that here:

physics-box2d-extension/applyforce-how-do-i-get-force-based-on-a-velocity-t1740.html

Any help would be appreciated!
brash
 
Posts: 357
Joined: Thu Jan 20, 2011 11:44 pm

Re: Using a kinetic body instead of a MouseJoint?

Postby cat555 » Wed Jul 13, 2011 3:33 pm

Hi Brash, i'm having the same difficulty as you on this... did you found any solution for this?
Thanks, Carlos
Regards,
Carlos V.
--
Check My Apps done with AndEngine:
cat555
 
Posts: 35
Joined: Fri Oct 22, 2010 4:28 pm
Location: Portugal

Re: Using a kinetic body instead of a MouseJoint?

Postby Samdekkol » Thu Aug 13, 2015 8:51 pm

A great exchange of information.
Samdekkol
 
Posts: 15
Joined: Thu Aug 13, 2015 7:21 pm


Return to Physics Box2D

Who is online

Users browsing this forum: No registered users and 6 guests