What I’m trying to do is take the angle of the ship and apply force to it, so the body moves in the
direction of the mouse as well as the angle/rotation.
I can’t figure the applyForce(force, point, wake) method out. If that is what I’m actually looking for.
So far I have:
public void update(float camPosX, float camPosY){
//The mouse position
mouseP.x = (Gdx.input.getX()+playerSprite.getWidth()/2);
mouseP.y = -((Gdx.input.getY()-ScreenGlobals.HEIGHT));
//If W is pressed apply thrust
if(Gdx.input.isKeyPressed(Keys.W)){
body.applyForceToCenter( (mouseP.x-ScreenGlobals.WIDTH/2)*50f, (mouseP.y-ScreenGlobals.HEIGHT/2)*50, true );
// body.applyForce(force, point, true); //I'm not sure how to do this properly
}
//Set sprite position to match body position
float sox = x-playerSprite.getHeight()/2, soy = y-+playerSprite.getWidth()/2;
playerSprite.setPosition(sox, soy);
playerSprite.setRotation((body.getAngle()-(90*MathUtils.degreesToRadians))*MathUtils.radiansToDegrees);
}
That only moves the body in the direction of the mouse and doesn’t change the angle/rotation of the ship.
What I’m guessing by using applyForce(force, point, wake), is where “force” is the amount of force in which direction,
and point is where the force is applied to at that point on the body. So like a motor on a speed boat.
If this is what I need to achieve this, how is it used to apply force to the bottom of a 32*32 pixel sized
body in the direction of the mouse so the angle/rotation of the ship also faces the mouse?
I’ve tried a bunch of trigonometry stuff but can’t get anything to apply to the physics correctly I’m pretty new to LibGDX.
What it looks like:
WK4Bl5vIKfw
Thanks