# How can I create top down mouse-driven aiming? (Crosshair follows cursor, fires projectiles at cursor location)

**URL:** <https://forums.unrealengine.com/t/how-can-i-create-top-down-mouse-driven-aiming-crosshair-follows-cursor-fires-projectiles-at-cursor-location/279212>\
**Category:** UI\
**Tags:** crosshair, cursor, unreal-engine, twin-stick, shooter, top-down, question\
**Created:** [March 31, 2014, 10:56pm UTC](https://forums.unrealengine.com/t/how-can-i-create-top-down-mouse-driven-aiming-crosshair-follows-cursor-fires-projectiles-at-cursor-location/279212 "2014-03-31T22:56:57Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![darkpivot](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@darkpivot](https://forums.unrealengine.com/u/darkpivot)\
**Post date:** [March 31, 2014, 10:56pm UTC](https://forums.unrealengine.com/t/how-can-i-create-top-down-mouse-driven-aiming-crosshair-follows-cursor-fires-projectiles-at-cursor-location/279212/1 "2014-03-31T22:56:57Z")

</div>

So I have my top-down character mechanics in place. How would I go about having a 2D crosshair follow the mouse, so that I could fire projectiles in the direction the crosshair is. It’s in a top-down perspective, so it’s basically a twin-stick shooter mechanic.

---

<div class="post-metadata">

**Author:** ![PeterLNewton](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@PeterLNewton](https://forums.unrealengine.com/u/PeterLNewton)\
**Post date:** [April 1, 2014, 5:54am UTC](https://forums.unrealengine.com/t/how-can-i-create-top-down-mouse-driven-aiming-crosshair-follows-cursor-fires-projectiles-at-cursor-location/279212/2 "2014-04-01T05:54:22Z")

</div>

Hey **DarkPivot** ,

I hope this helps shine some light on your question. If you use the section where I get the Mouse Coordinates for the Crosshair, and apply that to the direction the projectile needs to go. I believe that should do it. Let me know if I missed something.

**Notes:** _Make sure the Crosshair Texture is drawn last within the stack to ensure it overlays every other HUD object. This BluePrint was a parent of the HUD class._

_Peace_

## Adding Custom Crosshair & Getting Mouse X/Y

 ![2907-drawing+custom+cursor.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/4/b/94be6be6090f9e5f3ced6287a9b58b70df7e1d4a.jpeg)

---

<div class="post-metadata">

**Author:** ![itsAcren](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/itsacren/32/1194653_2.png) [@itsAcren](https://forums.unrealengine.com/u/itsAcren)\
**Post date:** [April 1, 2014, 9:03am UTC](https://forums.unrealengine.com/t/how-can-i-create-top-down-mouse-driven-aiming-crosshair-follows-cursor-fires-projectiles-at-cursor-location/279212/3 "2014-04-01T09:03:04Z")

</div>

Are you asking how to make the mouse visible or how to actually fire at the mouse?

* * *

## **Show a basic crosshair on the mouse**

In the controller defaults:

 ![2908-crosshair.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/9/d/e9d983f1ad5cf15695378c9be52063087aa497a7.png)

* * *

## Get mouse in world space

Check my answer here:

> **[Topics tagged unreal-engine](https://forums.unrealengine.com/tags/intersection/unreal-engine/question)**
>
> Topics tagged unreal-engine

---

<div class="post-metadata">

**Author:** ![darkpivot](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@darkpivot](https://forums.unrealengine.com/u/darkpivot)\
**Post date:** [April 1, 2014, 1:00pm UTC](https://forums.unrealengine.com/t/how-can-i-create-top-down-mouse-driven-aiming-crosshair-follows-cursor-fires-projectiles-at-cursor-location/279212/4 "2014-04-01T13:00:20Z")

</div>

Where am I making this blueprint, because I can’t find the HUD event.

---

<div class="post-metadata">

**Author:** ![darkpivot](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@darkpivot](https://forums.unrealengine.com/u/darkpivot)\
**Post date:** [April 1, 2014, 1:02pm UTC](https://forums.unrealengine.com/t/how-can-i-create-top-down-mouse-driven-aiming-crosshair-follows-cursor-fires-projectiles-at-cursor-location/279212/5 "2014-04-01T13:02:01Z")

</div>

Hmm, the show mouse cursor isn’t working for some reason. Also, I’m trying to to have the projectile fire towards the mouse, but I can’t find a way to modify its rotation/velocity towards the mouse coordinates.

---

<div class="post-metadata">

**Author:** ![PeterLNewton](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@PeterLNewton](https://forums.unrealengine.com/u/PeterLNewton)\
**Post date:** [April 1, 2014, 6:55pm UTC](https://forums.unrealengine.com/t/how-can-i-create-top-down-mouse-driven-aiming-crosshair-follows-cursor-fires-projectiles-at-cursor-location/279212/6 "2014-04-01T18:55:05Z")

</div>

You will need to create a BluePrint and make its parent the **HUD** class. The **HUD** class is under **Actor** class. When you go to create a new **Class Blueprint** , you must look under **Custom Classes** then Search for **HUD**

If you need instructions on how to do this, go to [Creation via Class Viewer](https://docs.unrealengine.com/latest/INT/Engine/Blueprints/UserGuide/Types/ClassBlueprint/Creation/index.html#creationviaclassviewer) in the lower section of this BluePrint Creation Example.

_Review Acren’s post below, simply changing the Set Rotation Node to the Spawn Actor from Class, then set its Rotation. Depending how you have your Top Down Setup, it may be relevant to set the Actors Rotation. IE, If your gun follows the Actor, Set Actor. IE, If you Actor follows the Gun, Set Projectile Rotation_

---

<div class="post-metadata">

**Author:** ![darkpivot](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@darkpivot](https://forums.unrealengine.com/u/darkpivot)\
**Post date:** [April 1, 2014, 9:01pm UTC](https://forums.unrealengine.com/t/how-can-i-create-top-down-mouse-driven-aiming-crosshair-follows-cursor-fires-projectiles-at-cursor-location/279212/7 "2014-04-01T21:01:20Z")

</div>

man, you’re helping a ton. Any idea why my crosshair texture just draws as a white box? I have it set in the Draw Texture node, but no matter what I do, it is just a box, even though the texture is a crosshair (with alpha channel). I’ve tried messing with the tint color (changing the alpha value, etc.) and blend mode but nothing works.

---

<div class="post-metadata">

**Author:** ![PeterLNewton](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@PeterLNewton](https://forums.unrealengine.com/u/PeterLNewton)\
**Post date:** [April 1, 2014, 9:37pm UTC](https://forums.unrealengine.com/t/how-can-i-create-top-down-mouse-driven-aiming-crosshair-follows-cursor-fires-projectiles-at-cursor-location/279212/8 "2014-04-01T21:37:29Z")

</div>

Have you tried using **Draw Texture Simple**? Draw Texture is more complex, but gives you more control.

### _Draw Texture Simple_
 simply needs the Texture, X & Y location provided by the Setup Above.

### _Draw Texture_
 needs the Texture, X & Y, Screen W & Screen H sets Width & Height, Texture U & V can be ignored, but this moves Top Left origin in UV Space, Texture UWidth & VHeight are the scale in relation to the Width & Height, Set these to 1 usually, Blend Mode can be changed to what you desire.

### _Draw Texture Explained_
  
To further elaborate the uses for **Draw Texture**. Texture U & V allow setting the _Top Left_ Draw Point of Texture. So if you were using a sprite sheet or any texture with multiple Images. You would set this to start in a position within the texture, then set the Screen W & H to draw the size of the image within that area. UWidth & VHeight could be used to Tile the texture. This tells the texture spaces within the UV. _Does it have 1, 2, or 3 spaces?_ Setting it to 2 / 2 will have the texture repeat 4 times within the given Width & Height aka UV Space. 2 / 1 will print 2, but stretch it horizontally to fill the UV Space.

---

<div class="post-metadata">

**Author:** ![darkpivot](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@darkpivot](https://forums.unrealengine.com/u/darkpivot)\
**Post date:** [April 1, 2014, 9:43pm UTC](https://forums.unrealengine.com/t/how-can-i-create-top-down-mouse-driven-aiming-crosshair-follows-cursor-fires-projectiles-at-cursor-location/279212/9 "2014-04-01T21:43:34Z")

</div>

That’s what I am using. It still just draws as a box (whatever the tint color is). I haven’t tried the simple version yet though. I’ll try that when I get home, but I have a feeling it won’t make a difference.

---

<div class="post-metadata">

**Author:** ![PeterLNewton](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@PeterLNewton](https://forums.unrealengine.com/u/PeterLNewton)\
**Post date:** [April 1, 2014, 9:49pm UTC](https://forums.unrealengine.com/t/how-can-i-create-top-down-mouse-driven-aiming-crosshair-follows-cursor-fires-projectiles-at-cursor-location/279212/10 "2014-04-01T21:49:40Z")

</div>

Its possible you didn’t set the UWidth & VHeight properly. Setting it to a high number will result in a color of the texture itself. _Repeating it so much, its most prominent color is only shown._ Setting this to 1, will tell the Texture to draw once within the UV Space. Thus showing the texture in its full clarity.

---

<div class="post-metadata">

**Author:** ![darkpivot](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@darkpivot](https://forums.unrealengine.com/u/darkpivot)\
**Post date:** [April 1, 2014, 11:42pm UTC](https://forums.unrealengine.com/t/how-can-i-create-top-down-mouse-driven-aiming-crosshair-follows-cursor-fires-projectiles-at-cursor-location/279212/11 "2014-04-01T23:42:24Z")

</div>

UWidth & VHeight don’t do anything, but Simple Draw Texture actually works fine. I just have to put the scale to 0.05. However, it seems slightly off from the actual mouse position.

Edit: Actually 0.04 is perfectly on center with the mouse position, and it looks better. ! Now I just gotta figure out the projectile part. I can get it to fire when clicking, but I can’t get it to fire from the player position or in the direction of the mouse.

---

<div class="post-metadata">

**Author:** ![PeterLNewton](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@PeterLNewton](https://forums.unrealengine.com/u/PeterLNewton)\
**Post date:** [April 1, 2014, 11:51pm UTC](https://forums.unrealengine.com/t/how-can-i-create-top-down-mouse-driven-aiming-crosshair-follows-cursor-fires-projectiles-at-cursor-location/279212/12 "2014-04-01T23:51:27Z")

</div>

If you change the scale of the image, they wouldn’t be its true resolution. You will have to make the formula Resolution \* 0.05 / 2, then subtract that from the X & Y. So **resolution\*Scale/2** would center the Crosshair. I can provide an example after UE4 updates.

---

<div class="post-metadata">

**Author:** ![darkpivot](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@darkpivot](https://forums.unrealengine.com/u/darkpivot)\
**Post date:** [April 1, 2014, 11:55pm UTC](https://forums.unrealengine.com/t/how-can-i-create-top-down-mouse-driven-aiming-crosshair-follows-cursor-fires-projectiles-at-cursor-location/279212/13 "2014-04-01T23:55:59Z")

</div>

Ah that makes sense. .

---

<div class="post-metadata">

**Author:** ![PeterLNewton](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@PeterLNewton](https://forums.unrealengine.com/u/PeterLNewton)\
**Post date:** [April 2, 2014, 12:06am UTC](https://forums.unrealengine.com/t/how-can-i-create-top-down-mouse-driven-aiming-crosshair-follows-cursor-fires-projectiles-at-cursor-location/279212/14 "2014-04-02T00:06:25Z")

</div>

Sweet glad I could help. I learned more about the Draw Texture node just now. So the feeling is mutual. Acren below has a great example of generating a rotation based on Mouse Location. So check that out and you should be on your way.

---

<div class="post-metadata">

**Author:** ![darkpivot](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@darkpivot](https://forums.unrealengine.com/u/darkpivot)\
**Post date:** [April 2, 2014, 12:25am UTC](https://forums.unrealengine.com/t/how-can-i-create-top-down-mouse-driven-aiming-crosshair-follows-cursor-fires-projectiles-at-cursor-location/279212/15 "2014-04-02T00:25:57Z")

</div>

My problem is that I can’t get the rotation to apply to the projectile, or have it spawn at the actor for that matter. Even this:

 ![2975-ss+(2014-04-01+at+08.23.11).png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/a/6/aa67ab2e6e78a2ab7cf62c9d1f8efc928c103d21.png)

doesn’t spawn it at the actor location, only the place where it spawns.

---

<div class="post-metadata">

**Author:** ![PeterLNewton](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@PeterLNewton](https://forums.unrealengine.com/u/PeterLNewton)\
**Post date:** [April 2, 2014, 8:16am UTC](https://forums.unrealengine.com/t/how-can-i-create-top-down-mouse-driven-aiming-crosshair-follows-cursor-fires-projectiles-at-cursor-location/279212/16 "2014-04-02T08:16:03Z")

</div>

If that is located within the Pawn Class firing that Projectile, it should work fine. I can only assume there is a problem with the Projectile itself.

Try reviewing this video for a step by step process of setting up projectiles.  
https://www.youtube.com/embed/ojvuTz4KCfE?feature=oembed&wmode=opaque&list=PLZlv_N0_O1gaG5BW72It4chjhypxIO9ZB

---

<div class="post-metadata">

**Author:** ![darkpivot](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@darkpivot](https://forums.unrealengine.com/u/darkpivot)\
**Post date:** [April 2, 2014, 1:57pm UTC](https://forums.unrealengine.com/t/how-can-i-create-top-down-mouse-driven-aiming-crosshair-follows-cursor-fires-projectiles-at-cursor-location/279212/17 "2014-04-02T13:57:18Z")

</div>

Nope… still the same. It just fires in one direction and spawns in the location the player started at.

---

<div class="post-metadata">

**Author:** ![Jenovah\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Jenovah\_1](https://forums.unrealengine.com/u/Jenovah_1)\
**Post date:** [April 2, 2014, 4:13pm UTC](https://forums.unrealengine.com/t/how-can-i-create-top-down-mouse-driven-aiming-crosshair-follows-cursor-fires-projectiles-at-cursor-location/279212/18 "2014-04-02T16:13:37Z")

</div>

Yeah when you try to apply this into the top down blueprint it shoots the projectile only from the origin point, I am curious how this is done also. I saw a “get mouse position” function but I had no luck hooking things up. Super curious how this is done.

---

<div class="post-metadata">

**Author:** ![PeterLNewton](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@PeterLNewton](https://forums.unrealengine.com/u/PeterLNewton)\
**Post date:** [April 2, 2014, 9:27pm UTC](https://forums.unrealengine.com/t/how-can-i-create-top-down-mouse-driven-aiming-crosshair-follows-cursor-fires-projectiles-at-cursor-location/279212/19 "2014-04-02T21:27:01Z")

</div>

Is this a Custom Pawn Class made by you or using Premade Examples?

---

<div class="post-metadata">

**Author:** ![darkpivot](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@darkpivot](https://forums.unrealengine.com/u/darkpivot)\
**Post date:** [April 2, 2014, 10:42pm UTC](https://forums.unrealengine.com/t/how-can-i-create-top-down-mouse-driven-aiming-crosshair-follows-cursor-fires-projectiles-at-cursor-location/279212/20 "2014-04-02T22:42:24Z")

</div>

Self made. It’s basically a rolling ball from a top down perspective (see the game "Waves’). There’s a thread I made about it in the blueprint section of the forums.

[Next page](https://forums.unrealengine.com/t/how-can-i-create-top-down-mouse-driven-aiming-crosshair-follows-cursor-fires-projectiles-at-cursor-location/279212.md?page=2)
