0

I have a game where the main character is on the far left side of the screen (landscape) in the middle. He rotates using the accelerometer. Hes going to be shooting bullets constantly and I need a way to make the bullets fire depending on his rotation.

So basically I dont know the math to make the bullet fire straight depending on the sprites rotation.

Any help appreciated.

Edit:

I know my question is kind of vague, I dont really know how to ask it.

My character is a top view of a turret, he will rotate when you rotate your phone, and obviously as he rotates, the bullets still need to shoot straight. I just dont know the math to make this happen.

1
  • How do you fire your bullets? I mean in the code. It'd be better to provide more info on what is your actual problem. Also a screenshot from the game would be great.
    – krafter
    Sep 22, 2013 at 16:18

1 Answer 1

1

I assume you know how get values from accelerometer and the character "rotates" up and down (angry birds style).

If you fire your bullets by some amount of coordinates (moveBy(x,y) ) - just use more y to fire up. To fire down use more x.

For example: To fire in straight line - moveBy(10,10)

To fire up - moveBy(10,20);

To fire dowp - moveBy(20,10);

General case - moveBy(x*accelerometerVal, y*(1/accelerometerVal) );

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.