Jump to content
  • Advertisement
Sign in to follow this  
Subscript

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!