Hello, i am really struggling to make a body follow the mouse position. I really read and tried many things from the documentation, online examples etc.
I am creating a physics world and a body in it. I want to make the object always follow the mouse position but i see there is no method helping this. There are only methods for applying forces, impulse and initialization of the body.
I read and tried things like creating mouseJoint but i was not able to have a successful result.
I am wondering if i need to destroy the object and create a new one every time.
Here is what i am trying:
///Import libraries relating to Box2D Physics engine
Body rabbit_body; //my body
PImage rabbit; //image following my body
rabbit = loadImage("hopr.gif");
bg = loadImage("grass.jpg");
//Set up the physics world
physics = new Physics(this,
///Set up my physics object
rabbit_body = physics.createRect(100, 100, 120,180);
Vec2 screenBallPosition = physics.worldToScreen(rabbit_body.getWorldCenter());
float ballAngle = physics.getAngle(rabbit_body); ///Returns the angle in degrees
//make the image always follow the body
What i tried is the below line:
rabbit_body = physics.createRect(mouseX, mouseY, 120,180);
But is not working. I tried to put the line in the draw function or in the mousePressed but it's crashing.
Discuss issues specific the Java port of Box2D
1 post • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 2 guests