Question

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.

Was it helpful?

Solution 2

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.

OTHER TIPS

  Sprite  pSprite = new Sprite(23, 43, pTextureRegion, pVertexBufferObject);
    PhysicsHandler handler = new PhysicsHandler(pSprite);
    handler.setVelocityX(pVelocityX);
   handler.setVelocityY(pVelocityY);

In this way you can implement. If it is not adjusting then you can creating body for that particular sprite and apply force to that body

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top