A Flash Developer Resource Site

# Thread: Simple math problem (cannon rotation)

1. ## Simple math problem (cannon rotation)

Hi.

My problem is easy

I need to know how to how to make a bullet go in the same direction as the cannon points. I don't need curves or anything, just a straight line forward.

To explain a bit better: if the cannon points left, the bullet will go left... right-right, and so on for all 360 degrees.

I just suck at Math and I wanna make a simple minigame so ty for replies

2. Depends on how you are controlling the cannon. If you're moving it with Arrow Keys and changing its _rotation, then set the bullet the same as the cannon's _rotation, but if you're moving the cannon at the mouse's angle, then you'd still set the bullet's angle to the cannon's angle, aka, the _rotation. Tell me which it is, and I'll provide the correct Actionscript

AS2 or AS3?

3. The cannon actually rotates by itself. Only thing changing is the speed of the rotation (it can be negative, too)

So, when you press a key, the cannon shoots the object in the cannon in the facing direction in a straight line

Thats pretty much it

Edit: Oh and yeah, its _rotation, simple as that

thanks

4. The very basic movement based on rotation uses 2 equations, one for x and other for y coordinate:

//first convert _rotation from degrees into radians
ang = Math.PI * (cannon._rotation)/180;
//set the speed
speed = 5;
//change the coordinates
dx = speed * Math.cos(ang);
dy = speed * Math.sin(ang);
//now add the components to both coordinates in enterframe event
bullet.x += dx;
bullet.y += dy;

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap

Click Here to Expand Forum to Full Width