# Aiming in a 2D sidescroller problem - arrow does not follow the cursor

**URL:** <https://forums.unrealengine.com/t/aiming-in-a-2d-sidescroller-problem-arrow-does-not-follow-the-cursor/530467>\
**Category:** Blueprint\
**Tags:** unreal-engine, UE5-0, question, Blueprint\
**Created:** [April 16, 2022, 12:58pm UTC](https://forums.unrealengine.com/t/aiming-in-a-2d-sidescroller-problem-arrow-does-not-follow-the-cursor/530467 "2022-04-16T12:58:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mahri726](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mahri726](https://forums.unrealengine.com/u/mahri726)\
**Post date:** [April 16, 2022, 12:58pm UTC](https://forums.unrealengine.com/t/aiming-in-a-2d-sidescroller-problem-arrow-does-not-follow-the-cursor/530467/1 "2022-04-16T12:58:06Z")

</div>

Hello. I’ve been working on a 2.5D platformer and I’m trying to find a way to shoot projectiles at mouse location. Above the main character there is a floating weapon (for now replaced with an arrow component that will be parented to the gun mesh) that is supposed to rotate in such a way as to allow player to shoot enemies. I’ve been looking these days at several tutorials that could help me with this, but so far nothing works. I should also mention that I’m using Unreal Engine 5.00, in case that there are some changes from the previous versions that might interfere.

One of the things that I tried is from this thread:

> [@2D Side Scroller aim weapon at mouse cursor](https://forums.unrealengine.com/t/2d-side-scroller-aim-weapon-at-mouse-cursor/462122):
>
> Hi, I am trying to get my character’s gun to aim towards the position of my mouse. Here is the blueprint I am using; This works to an extent as the mouse is tracked on one side of the screen, but not on the other. (Red circle is mouse location) Thanks in advance for any help!

That has this Blueprint Graph solution:

 ![attempt1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/f/8/5f877acbe75b1a653a63b30a88b3f586c69125bb.jpeg)

However, the arrow component sticks up, moves a little and does not follow the cursor. I posted a gif here to explain, with values print screened for several vectors:  
 ![ezgif-4-f152e3c9f0](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/1/3/213a2180534712458039a7acc5bf9a10269c8f80.gif)

Another thing that I tried is from this thread:

> [@Aiming in a 2d side scroller](https://forums.unrealengine.com/t/aiming-in-a-2d-side-scroller/122436):
>
> Hello ! I’ve been searching around but i can’t find anything about that, so maybe someone can help me ? I’m looking for a way / tutorial in blueprint to do an aiming system who follows the cursor of the mouse, like in the game Starbound ! It’s very important because i need to do that before continuing the developpement of my game. I already found a turorial to do that i a 3d side scroller but it’s not compatible with a 2d one. Thanks a lot for your time, have a nice day ! slight_smile

 ![attempt2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/d/3/4d30f800028a9563fbe6d1a16461f67d8eb67bdd.jpeg)

And it still doesn’t work. The rotation value goes from 86 to 87 so the arrow stays almost still.

Do you know how could I solve this problem ? I would really need help with this.

---

<div class="post-metadata">

**Author:** ![BlackCryptix](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BlackCryptix](https://forums.unrealengine.com/u/BlackCryptix)\
**Post date:** [April 16, 2022, 1:31pm UTC](https://forums.unrealengine.com/t/aiming-in-a-2d-sidescroller-problem-arrow-does-not-follow-the-cursor/530467/2 "2022-04-16T13:31:41Z")

</div>

You have to project your mouse to the same y location as you character.  
Here an example on how to do it.

 ![grafik](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/1/c/b1cf22046266393b8d6b306b47b02d74371c9185.png)

---

<div class="post-metadata">

**Author:** ![mahri726](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mahri726](https://forums.unrealengine.com/u/mahri726)\
**Post date:** [April 16, 2022, 7:07pm UTC](https://forums.unrealengine.com/t/aiming-in-a-2d-sidescroller-problem-arrow-does-not-follow-the-cursor/530467/3 "2022-04-16T19:07:47Z")

</div>

Thank you very much ! I tried using your example script, and the arrow does indeed follow the cursor.

There is still a little problem. The arrow is not pointing just in XZ plane, it is pointing a bit outwards, in the Y axis. This could cause problems at a later stage, when shooting is implemented. I also tried to attach a gun mesh to the arrow, and it seems that the gun has another kind of rotation, in order to point outwards. I wonder how could I constrain the movement of the weapon/arrow in a single plane, like in 2D games.

 ![OFFSET2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/f/d/bfd8b27b3f6bea545253378cf430faec70f3a4c6.jpeg)

---

<div class="post-metadata">

**Author:** ![BlackCryptix](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BlackCryptix](https://forums.unrealengine.com/u/BlackCryptix)\
**Post date:** [April 16, 2022, 8:13pm UTC](https://forums.unrealengine.com/t/aiming-in-a-2d-sidescroller-problem-arrow-does-not-follow-the-cursor/530467/4 "2022-04-16T20:13:51Z")

</div>

Check if your character model is centered inside of the character actor. But to me it looks like your camera has an angled view on the scene. To fix this either remove the camera angle or adjust the solution to the follwing:

 ![grafik](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/5/f/45f4743eeab001a494626d4a5d922ead31fe081b.png)

To lock your character in the XZ plane use the settings inside of the CharacterMovementComponent:  
 ![grafik](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/8/4/5843bc61a4bd67f8aa0f40adeab613c2eb048eea.png)

---

<div class="post-metadata">

**Author:** ![mahri726](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mahri726](https://forums.unrealengine.com/u/mahri726)\
**Post date:** [April 17, 2022, 12:23pm UTC](https://forums.unrealengine.com/t/aiming-in-a-2d-sidescroller-problem-arrow-does-not-follow-the-cursor/530467/5 "2022-04-17T12:23:17Z")

</div>

I verified and the camera doesn’t have an angled view. However, it is turned at -90.000183 ° on the Z axis. I’m not sure that that approximation caused the issue. Anyway, I tried using the modified script, and everything works well. Thank you very much for your help !
