# sword direction?

**URL:** <https://forum.makecode.com/t/sword-direction/32310>\
**Category:** Help\
**Tags:** game\
**Created:** [December 8, 2024, 5:14am UTC](https://forum.makecode.com/t/sword-direction/32310 "2024-12-08T05:14:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sausage\_man](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/sausage_man/32/18628_2.png) [@Sausage\_man](https://forum.makecode.com/u/Sausage_man)\
**Post date:** [December 8, 2024, 5:14am UTC](https://forum.makecode.com/t/sword-direction/32310/1 "2024-12-08T05:14:22Z")

</div>

I’m trying to make my character face up, down, left, right, and I already have the walking animation but I need help with the attacking. My basic idea that I want is to make a projectile that starts and stops right in front of you while the character animation for swinging the plays for all discretion but I have yet to find a way to make it work.

-im already using the animation extension

---

<div class="post-metadata">

**Author:** ![AgentBoom](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/agentboom/32/16635_2.png) [@AgentBoom](https://forum.makecode.com/u/AgentBoom)\
**Post date:** [December 9, 2024, 1:55am UTC](https://forum.makecode.com/t/sword-direction/32310/2 "2024-12-09T01:55:22Z")

</div>

First off… Why did you post the same topic twce?  
Anyway, here’s a step-by-step solution (this is what I use):

1. First, I create a variable named LastDirection (or whatever you wish to call it).  
 ![Screenshot 2024-12-08 10.34.47](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/f/3/f38993f675c76e5abfe851c032a5c5c071142e11.png)
2. Next, I create _this_ piece of code. It changes the LastDirection variable depending on which direction button you last pressed.  
 ![Screenshot 2024-12-08 10.36.00](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/b/a/baf3ba575edd8fcba2e4eb9cb73a4ecd9f25112d.png)
3. Then, I make this big block that, for every time the attack button is pressed (A in my case), checks what the LastDirection was to determine which way the sword will be facing. So, it executes code that shoots the sword as a projectile, with a lifespan of 150 milliseconds, so that the sword disappears after a short stab.  
 ![Screenshot 2024-12-08 10.42.57](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/b/7/b74de87779ce91bea72c537120fd7f6f054549f5.png)

Here is the full project:

> **[Example for Sword Directions](https://arcade.makecode.com/S97630-55542-44120-28506)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

---

<div class="post-metadata">

**Author:** ![Sausage\_man](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/sausage_man/32/18628_2.png) [@Sausage\_man](https://forum.makecode.com/u/Sausage_man)\
**Post date:** [December 9, 2024, 2:58pm UTC](https://forum.makecode.com/t/sword-direction/32310/3 "2024-12-09T14:58:44Z")

</div>

i dont know why it posted it twice.  
but thanks this helps a lot! ill try

---

<div class="post-metadata">

**Author:** ![Sausage\_man](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/sausage_man/32/18628_2.png) [@Sausage\_man](https://forum.makecode.com/u/Sausage_man)\
**Post date:** [December 9, 2024, 2:58pm UTC](https://forum.makecode.com/t/sword-direction/32310/4 "2024-12-09T14:58:46Z")

</div>

also im new-ish to MakeCode
