Public Group

# Move towards rotation.

This topic is 2549 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?

1. 1
2. 2
Rutin
21
3. 3
A4L
15
4. 4
5. 5

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633740
• Total Posts
3013621
×