0
votes

Using AndEngine Physics Box2D i am trying to drag a body from side to side on the x axis.

This is what i have so far which isnt working correctly, the body moves up on the y axis and it doesnt follow the pointer(finger)

 int P2M = 32;
final Vector2 v2 = Vector2Pool.obtain(x / P2M, this.getY() / P2M);
body.setTransform(v2, 0); // if you want you can also set the rotation here
Vector2Pool.recycle(v2);

Anyone familiar with doing this?

2
how do you get x ? and what is your this object ?Greg
use b2MouseJoint. It was designed do move objects with mouse/fingersAndrew

2 Answers

2
votes

probably you should use body.getPosition().y instead of this.getY() but I don't know how do you get x ? if you use pSceneTouchEvent.getX() then it sould works

1
votes
Vector2 localPoint = Vector2Pool.obtain((pTouchAreaLocalX/PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT, (pTouchAreaLocalY/PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT);
body.setTransform(body.getWorldPoint(localPoint), 0);
Vector2Pool.recycle(localPoint);