简体   繁体   中英

Bullet firing in direction of rotation

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.

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) );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM