Public Group

# Move towards rotation.

This topic is 2860 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Alright, so I'm trying to make my bullets move towards the rotation. This is my code for it.
 function shoot(event:MouseEvent) { var bullet:MovieClip = new bullet_mc(); addChild(bullet); bullet.x = player.x; bullet.y = player.y; bullet.rotation = player.rotation; bullet.addEventListener(Event.ENTER_FRAME, moveBullets); } function moveBullets(event:Event):void { event.target.x += 10*Math.sin(event.target.rotation*(Math.PI/180)); event.target.y += 10*Math.cos(event.target.rotation*(Math.PI/180)); } 

Now the problem is, when I shoot right the bullets go down, when I shoot left the bullets go up, when I shoot down the bullets go right and when I shoot up the bullets go left. Appreciate all the help, thanks.

##### Share on other sites
event.target.x += 10*Math.sin((event.target.rotation+90)*(Math.PI/180));
event.target.y += 10*Math.cos((event.target.rotation+90)*(Math.PI/180));

yeah trig can be weird sometimes, sometimes you have to add or subtract 90 degrees

right - 90degrees = up
down - 90degrees=right
left - 90degrees=down
up - 90degrees=left
edit, hold, on, looks a bit different from that
are you sure shooting down causes them to go right, and not left? and if so, can you post how the players rotation is calculated.

##### Share on other sites
Actually, what the code for moving the bullets should be is dependent on how you define your rotations. Does your code to move the player (if there is any) use player.rotation, and if so what does said code look like?

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 15
• 9
• 11
• 15
• 21