Flashadvisor logo
:: Desktop Shortcut
:: Flash Help
Advices from Experts

 Submit Here! · Link to Us · Newsletter · Tell a Friend ·

      Add Tutorial |

 

Advertise here

Create Speaking Characters for your website and Flash movies. 15 Day Free Trial




PHP Scripts

 

 Home > Tutorials  > Advanced

Introduction to projectile motion

Author: Flabby Rabbit | Email


Advertisement


I am half way through my first yeah in sixth form and one of my subjects is
maths/mechanics, and after studying projectiles and the formulas related to
them I was inspired to create a game based around these principles. I then remembered
a game I had once played where some sort of animal jumped of a cliff and you
had to whack it as far as possible. I remember enjoying the game and wanted
to create something similar. If there any errors with any of my formulas, calculations
or code can someone please contact me so I can make the necessary changes, thank
you.


I started of by creating a test movie, which I will be explaining today. It
requires the user to type in two variables, velocity and the angle of trajectory.


Finished SWF:










This flash movie may run abit slower than expected, this is due to a lowered
frame rate.



First create a new movie, 544 x 222. Create a new layer,
naming the first one 'code' and the second one 'visual'. Now on the code layer,
there should be three key frames and on the visual layer there needs to be two
key frames then a normal frame. This should look like this:




With the visual layer:



On the first key frame you will need two axis and two dynamic
text boxes, one called 'velocity' the other 'angle'. I have also included two
movie clips that track the projectiles progress. The first is called 'hp' (highest
point) and includes a dynamic text box called 'h' and a line to horizontally
to the right. This is place with the line touching the y axis. The other movie
clip is called 'lp' (length point) and includes a variable text box, 'l' and
an arrow pointing vertically above; this is placed touching the x axis. The
next thing we need to do is create a small, highly visible circle which will
act as the projectile, convert this to a movie clip and call it ’mark’. Finally
we need to add a button, mine is labelled calc (calculate). This will all need
to be copied onto the second key frame, but with out the button. At this stage
it should look something like this:



The last thing to do on the visual layer is to add the code
to the button, this will be:





on (release) {

if (_root.angle<=90) {

if (_root.angle>0) {

// Calculates the horizontal speed

hor = _root.velocity*Math.cos(_root.angle/57.3);

// Calculates the vertical speed

ver = _root.velocity*Math.sin(_root.angle/57.3);

// Sets the value of gravity (-9.8 is gravity on earth)

g = -9.8;

// calculates the total time of flight

ot = ver/-g;

// goes and draws trajectory

gotoAndPlay(2);

}

}

}




The above code hopefully is quite straight forward to understand.
The inputed velocity and angle are converted to two seperate velocities, vertical
and horizontal, this then allows us to use SUVAT equations to calculate different
properties of the projectile motion. The main problem I had was with the ‘_root.velocity*Math.cos(_root.angle/57.3);’
due to flash giving out the result in radians and I was putting the angle in
as degrees I had to divide the angle by 57.3 to convert it to radians.


Download Source File

| 1 | 2 |

Rate This Tutorial :
We hope the information helped you. If you have any questions or comments, please don't hesitate to post them on the Forums section
Submit your Tutorial at Click Here
  

Home | About Us | Contact Us | Feedback | Advertise with us

Best viewed in 800x600 resolution with Internet Explorer.

Site Developed and Hosted by  ethicsolutions.com
All rights reserved with FlashAdvisor

Flash is a registered trademark of Adobe Systems, Inc.

13 users online