# Distance Specific Weapons

**URL:** <https://forum.kirupa.com/t/distance-specific-weapons/120103>\
**Category:** Uncategorized\
**Created:** [August 20, 2004, 5:28pm UTC](https://forum.kirupa.com/t/distance-specific-weapons/120103 "2004-08-20T17:28:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![OnionSkin](https://avatars.discourse-cdn.com/v4/letter/o/0ea827/32.png) [@OnionSkin](https://forum.kirupa.com/u/OnionSkin)\
**Post date:** [August 20, 2004, 5:28pm UTC](https://forum.kirupa.com/t/distance-specific-weapons/120103/1 "2004-08-20T17:28:41Z")

</div>

I am curious as to how the player in[font=Verdana] [/font]**[font=Verdana][size=2][color=black]"Alien Hominid[/color][/size][/font]**[color=black] **"** [/color]is coded to use a subweapon at close range. The main weapon is a gun, however if you press the attack button when an enemy is at close range the main character uses a different weapon (a la **Metal Slug** ). Any ideas as the best way to go about coding something like this?

---

<div class="post-metadata">

**Author:** ![Behemoth\_Dan](https://avatars.discourse-cdn.com/v4/letter/b/779978/32.png) [@Behemoth\_Dan](https://forum.kirupa.com/u/Behemoth_Dan)\
**Post date:** [August 20, 2004, 6:33pm UTC](https://forum.kirupa.com/t/distance-specific-weapons/120103/2 "2004-08-20T18:33:09Z")

</div>

What you could do, is when it attacks, have it check the distance between the two movieclips. Subtract the x values from each other, and then the Y values, and get the absolute value. Then, if both these numbers are say, less than 5, have it play one animation, and if it is farther than whtever distance, have it play the other animation.

You would have this all in a function that is callled when you press the attack button or something to that extent.

---

<div class="post-metadata">

**Author:** ![OnionSkin](https://avatars.discourse-cdn.com/v4/letter/o/0ea827/32.png) [@OnionSkin](https://forum.kirupa.com/u/OnionSkin)\
**Post date:** [August 21, 2004, 11:26am UTC](https://forum.kirupa.com/t/distance-specific-weapons/120103/3 "2004-08-21T11:26:04Z")

</div>

Great suggestion, Dan. I will have to give that a try.
