# Creating realistic flight of an arrow

**URL:** <https://forum.kirupa.com/t/creating-realistic-flight-of-an-arrow/63829>\
**Category:** flash\
**Created:** [September 10, 2004, 10:46am UTC](https://forum.kirupa.com/t/creating-realistic-flight-of-an-arrow/63829 "2004-09-10T10:46:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tommythewolfboy](https://avatars.discourse-cdn.com/v4/letter/t/b38774/32.png) [@tommythewolfboy](https://forum.kirupa.com/u/tommythewolfboy)\
**Post date:** [September 10, 2004, 10:46am UTC](https://forum.kirupa.com/t/creating-realistic-flight-of-an-arrow/63829/1 "2004-09-10T10:46:17Z")

</div>

I’m trying to put together some code that will approximate the arced flight of an arrow.  
Currently, I’ve got the code so that the angle of the bow movieclip will move depending upon the position of the mouse. Pressing the mousebutton will then fire an arrow at this angle (albeit at a constant speed). I’ve played around with xmov and ymov in an attempt to introduce inertia and gravity (respectively) and therefore create a more natural flight of the arrow but aren’t really getting what I’m after. Added to this, I also need to alter the angle of the arrow clip over the course of it’s flight to imitate the charge in orientation (i.e. starts to point towards the ground in the downward 1/2 of the arc). Code so far is below.

Does anyone have any suggestions? Or even alternatives (such as draw a curve with the curveTo method and then animate the arrow clip along this path? … LOL, or is this simply wild/hopeful speculation on my part)

speed = 25;  
// calculate angle based upon mouse position  
\_root.onMouseMove = function() {  
updateAfterEvent();  
xdiff = \_root.\_xmouse-bow\_mc.\_x;  
ydiff = \_root.\_ymouse-bow\_mc.\_y;  
angle = Math.atan2(ydiff, xdiff);  
angle = angle_180/Math.PI;  
bow\_mc.\_rotation = angle;  
};  
// fire arrow at this angle when MB clicked  
\_root.onMouseDown = function() {  
angle = bow\_mc.\_rotation;  
angle = angle_Math.PI/180;  
++depth;  
clipName = “arrow”+depth;  
clip = \_root.attachMovie(“arrow”, clipName, depth);  
clip.\_rotation = bow\_mc.\_rotation; // gives the arrow the same orientation as the bow when it is fired)  
clip.\_x = bow\_mc.\_x_Math.cos(angle);  
clip.\_y = bow\_mc.\_y_Math.sin(angle);  
clip.xmov = speed_Math.cos(angle);  
clip.ymov = speed_Math.sin(angle);  
clip.onEnterFrame = function() {  
this.\_x += this.xmov;  
this.\_y += this.ymov;  
};  
};

Many thanks!! Wishing I’d gone to a few more physics lessons at school now ;¬)

t

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 10, 2004, 3:48pm UTC](https://forum.kirupa.com/t/creating-realistic-flight-of-an-arrow/63829/2 "2004-09-10T15:48:16Z")

</div>

I did a post about almost the same thing here: [http://www.kirupaforum.com/forums/showthread.php?t=61456](http://www.kirupaforum.com/forums/showthread.php?t=61456)

If that dosen’t help, PM me.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 13, 2004, 1:12pm UTC](https://forum.kirupa.com/t/creating-realistic-flight-of-an-arrow/63829/3 "2004-09-13T13:12:56Z")

</div>

Thanks for the ‘heads up’, Jeremy. Much appreciated :¬)  
For anyone who is interested, in the end, I actually developed an amended version of the ‘Tutorial for Flash ballistics’ on [http://rachel.ns.purchase.edu/~Jeanine/flashlabs.html](http://rachel.ns.purchase.edu/~Jeanine/flashlabs.html) which details how to calculate a parabolic arc.
