Search code examples
androidbox2dandengine2d-gamesgoogle-play-games

I want to apply force in the facing direction of a sprite


I am developing a game in andengine and I want to apply a Force to my Sprite. The thing is I rotate the sprite with a controller and I want a force to be applied on the direction the sprite is facing (Sprite is a rocket).

Thanks in advance hope I explained it well.


Solution

  • I found the facing direction using this

    currentVelocity = new Vector2((float)Math.cos(body.getAngle()) * magnitude, (float) Math.sin(body.getAngle()) * magnitude);
        body.applyForce(currentVelocity, body.getPosition());
    

    magnitude is a float variable.