Object not moving using MouseJoint

Thanks everyone for replying..

I have moved my mouseJoint creation code in my init function (only once) and it seems to be working but now I am having trouble determining exactly what to pass to SetTarget.
I am using CoCos2d as game framework

I am trying to move an object (X) using mouseJoint towards object (Y)

Y is defined as a b2Body.
_mouseJoint is set up for Object X

//position of where I want my object to move to
b2Vec2 b2Position = b2Vec2(Y->GetPosition().x *PTM_RATIO,Y->GetPosition().y*PTM_RATIO));

//move object to desired position
_mouseJoint->SetTarget(b2Position);

On launch, the object moves towards one end of the screen and not towards Y. So I tried

_mouseJoint->SetTarget(0,0)

What I expected to happen is that X would move towards the lower corner (0,0) of the screen. Instead, it didn't move at all.
It seems like setTarget is taking in a "force" instead of a location.

What exactly am I supposed to pass ?
Supposing your PTM_RATIO is a ratio from pixels to meters: you don't have to use it here ! you must not convert coordinates when passing them from box2d to itself (like from GetPosition to SetTarget here). It needs to be used to convert box2d coordinates to your custom coordinates (like screen coordinates).

That does not explain your 0,0 problem, but you might want to review your whole coordinate systems at this point before going on.

I Hope that helps ...
Thanks for the reply!

I have made the following changes

Initially Ball object and Computer object have the same X value
I want the ball to follow computer object along the x axis as it moves, ie: Ball object follows Computer object Side by Side


b2Position = b2Vec2(ball->GetPosition().x,ball->GetPosition().y);
NSLog(@"Ball X = %f, Y=%f", ball->GetPosition().x,ball->GetPosition().y);
NSLog(@"Computer X = %f, Y=%f",computer->GetPosition().x,computer->GetPosition().y);

When I run this and move the computer object, both X are equal, so I am getting the right X value

As soon as I set

_mouseJoint->SetTarget(b2Position);

And I Print the same log messages

ball->GetPosition().x,ball doubles that of Computer->GetPosition().x

So on launch, the ball object is to the RIGHT hand side of the computer, its as if SetTarget is "ADDING" to the coordinates.

From my understanding, it just sets it to the location.

What am I doing wrong here <tears>

Original thread: https://box2d.org/forum/viewtopic.php?t=4881