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


With the code layer:



Now for the code, on the first key frame we need this:



ot = 0;

stop();


which simply sets time to 0 and then waits. The third frame
is also very simple:



gotoAndPlay(2);



Which just loops the movie back round to calculate the next
position of the projectile. Now for the tricky bit, the second frame. I will
show you the code first then explain it:



tp = tp+(1/24);

if (tp>ot*2) {

gotoAndStop(1);

} else {

// height

height = Math.round((ver*tp)-4.9*(tp*tp));

_root.mark._y = 182.5-(height*0.3202);

if (182.5-(height*0.3202) < _root.hp._y) {

_root.hp._y = 182.5-(height*0.3202);

_root.hp.h = height+'m';

}

// range

range = Math.round((hor*(tp*2))/2);

setProperty(_root.mark, _x, 187.8+(range*0.3356));

_root.lp._x = 187.8+(range*0.3356);

_root.lp.l = range+'m';

}

Every time this code is run it calculates the time passed
by adding 1/24 to the previous time (change the 24 to the frame rate your movie
is running at). This means that the projectile runs at real time, the higher
the frame rate the smoother the curve will look. It then checks to see if the
tp (time passed) has exceeded the op (overall time), if it has then it goes
back to frame 1 else it re calculates the height and range of the projectile.
It also moves the markers to the corresponding positions on the y and x axis.
The if statement for the y marker just means that it stays at the highest point.
I was not pleased with just seeing where the projectile was I wanted to see
the whole path that it had travelled along so I adapted the code to this:





tp = tp+(1/24);

if (tp>ot*2) {

gotoAndStop(1);

} else {

i = i+1;

duplicateMovieClip(_root.mark, "mark"+i, i);

// height

height = Math.round((ver*tp)-4.9*(tp*tp));

_root.mark._y = 182.5-(height*0.3202);

if (182.5-(height*0.3202) < _root.hp._y) {

_root.hp._y = 182.5-(height*0.3202);

_root.hp.h = height+'m';

}

// range

range = Math.round((hor*(tp*2))/2);

setProperty(_root.mark, _x, 187.8+(range*0.3356));

_root.lp._x = 187.8+(range*0.3356);

_root.lp.l = range+'m';

}

The only difference is that it duplicates the mark movie
clip therefore drawing the path. If you do not understand any part of this download
the zip file and see it working or don’t hesitate to email me.

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.

10 users online