# Have a turret rotate towards crosshair?

**URL:** <https://forums.unrealengine.com/t/have-a-turret-rotate-towards-crosshair/316480>\
**Category:** UI\
**Tags:** crosshair, turret, unreal-engine, question\
**Created:** [April 26, 2015, 5:12pm UTC](https://forums.unrealengine.com/t/have-a-turret-rotate-towards-crosshair/316480 "2015-04-26T17:12:54Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Taurian](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Taurian](https://forums.unrealengine.com/u/Taurian)\
**Post date:** [April 26, 2015, 5:12pm UTC](https://forums.unrealengine.com/t/have-a-turret-rotate-towards-crosshair/316480/1 "2015-04-26T17:12:54Z")

</div>

What’s a good way to have a turret rotate towards a crosshair?

---

<div class="post-metadata">

**Author:** ![KeltRivera\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@KeltRivera\_1](https://forums.unrealengine.com/u/KeltRivera_1)\
**Post date:** [April 26, 2015, 5:26pm UTC](https://forums.unrealengine.com/t/have-a-turret-rotate-towards-crosshair/316480/2 "2015-04-26T17:26:03Z")

</div>

You should use “Make Rot From X” node. The input vector for this node should be (crosshair\_location - turret\_location). The output will be Rotator which you can youse for SetActorRotation node. You may also use just yaw component if you meet some issues or need only z-axis rotation (just use MakeRotation node and get yaw from your obtained rotator and other components form your turret’s original rotation)

It may look like this:

 ![40326-111.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/c/c/2ccc2723c7e1fcc1f6f3fa3fc4a45c55c32b8f95.png)

Hope that helps.

---

<div class="post-metadata">

**Author:** ![Taurian](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Taurian](https://forums.unrealengine.com/u/Taurian)\
**Post date:** [April 27, 2015, 3:43am UTC](https://forums.unrealengine.com/t/have-a-turret-rotate-towards-crosshair/316480/3 "2015-04-27T03:43:48Z")

</div>

The turret is actually a component on the pawn that I’m controlling. I’ve copied the nodes as much as I can but the turret appears to have a mind of it’s own:

 ![40347-capture.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/c/2/5c2611e65e3547f85a37daa683cd7bc08488dbbd.png)

---

<div class="post-metadata">

**Author:** ![KeltRivera\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@KeltRivera\_1](https://forums.unrealengine.com/u/KeltRivera_1)\
**Post date:** [April 27, 2015, 1:55pm UTC](https://forums.unrealengine.com/t/have-a-turret-rotate-towards-crosshair/316480/4 "2015-04-27T13:55:53Z")

</div>

Everything should work like a charm. You should check:

1. Your turrent component alignment (x axis should be along the trunk, z - upwards)
2. Correctness of your function for converting mouse input to aim coordinates (may be try to draw the debug sphere to check it).

I was up to perfofrming simple test for you and here’s results:

1)test turret blueprint (note the axis alignment)

 ![40403-turret_bp.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/2/6/c26b0e3f54532389a5b7d6fe95c366e2a02599d2.jpeg)

2)turrent blueprint tick function

 ![40404-turret_aim_bp1.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/f/9/8f9588e6c62e8557712320acf13d3a3f510455d0.jpeg)

1. the result

 ![40405-turret_aim1.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/e/2/9e2b82b5da6d5d59d2a27f332a2d0ba8da064a53.jpeg)

And the same for “locked axis” rotation I mentioned before: (not that turrent is rotated towards the aim, but it does not look upwards to it in this case)

 ![40406-turret_aim_bp2.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/d/b/cdb89bb05a3d726aa05c4b9818458a23992af947.jpeg)

 ![40407-turret_aim2.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/2/c/82c8874bf8e9e6a9a80f54eb2ae4597106b1b1c2.jpeg)

---

<div class="post-metadata">

**Author:** ![Taurian](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Taurian](https://forums.unrealengine.com/u/Taurian)\
**Post date:** [April 27, 2015, 3:40pm UTC](https://forums.unrealengine.com/t/have-a-turret-rotate-towards-crosshair/316480/5 "2015-04-27T15:40:49Z")

</div>

It’s pointing to the mouse “literally”. So it’s always pointing “backwards” towards the mouse. (Since the camera is behind the turret).

Is there a quick way to reverse this? Or should I try pointing it towards a cross hair material in front of the actor?

 ![40410-capture.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/b/b/4bb5e2a76940ba79db237396dab4c9dec984d9f8.png)

---

<div class="post-metadata">

**Author:** ![KeltRivera\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@KeltRivera\_1](https://forums.unrealengine.com/u/KeltRivera_1)\
**Post date:** [April 27, 2015, 4:06pm UTC](https://forums.unrealengine.com/t/have-a-turret-rotate-towards-crosshair/316480/6 "2015-04-27T16:06:23Z")

</div>

You should basically cast the ray from your camera and get the location of this hit. However for the mouse it looks like there is simlier solution. Just look at the accepted answer here: [Have a static mesh follow the mouse? - Asset Creation - Epic Developer Community Forums](https://answers.unrealengine.com/questions/148930/have-a-static-mesh-follow-the-mouse.html)

Good luck with your project.

---

<div class="post-metadata">

**Author:** ![Taurian](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Taurian](https://forums.unrealengine.com/u/Taurian)\
**Post date:** [April 27, 2015, 5:17pm UTC](https://forums.unrealengine.com/t/have-a-turret-rotate-towards-crosshair/316480/7 "2015-04-27T17:17:56Z")

</div>

It didn’t work. I think the solution is some how related to the “World Direction.”

I’ll keep trying.

---

<div class="post-metadata">

**Author:** ![KeltRivera\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@KeltRivera\_1](https://forums.unrealengine.com/u/KeltRivera_1)\
**Post date:** [April 27, 2015, 8:13pm UTC](https://forums.unrealengine.com/t/have-a-turret-rotate-towards-crosshair/316480/8 "2015-04-27T20:13:53Z")

</div>

Now looking at cursor crosshair (pretty good):

 ![40439-look_at_cursor.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/7/3/a734a4efaee4f7564aee5c327cad071a52bd45f2.jpeg)

and corresponding blueprint:

 ![40440-look_at_cursor_bp.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/7/3/a738905f00b80923e4a1780a2610d3261a25ff88.jpeg)

---

<div class="post-metadata">

**Author:** ![KeltRivera\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@KeltRivera\_1](https://forums.unrealengine.com/u/KeltRivera_1)\
**Post date:** [April 27, 2015, 8:17pm UTC](https://forums.unrealengine.com/t/have-a-turret-rotate-towards-crosshair/316480/9 "2015-04-27T20:17:41Z")

</div>

May be you can post some screenshot\more info on your setting? Still not sure if your turret’s first person, third person or top-down

---

<div class="post-metadata">

**Author:** ![Taurian](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Taurian](https://forums.unrealengine.com/u/Taurian)\
**Post date:** [April 27, 2015, 8:21pm UTC](https://forums.unrealengine.com/t/have-a-turret-rotate-towards-crosshair/316480/10 "2015-04-27T20:21:53Z")

</div>

It’s third person. I was able to get it to work with this though:

 ![40455-capture.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/6/1/36183d360d2e2579d9688824883cfb06479711d5.png)

---

<div class="post-metadata">

**Author:** ![KeltRivera\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@KeltRivera\_1](https://forums.unrealengine.com/u/KeltRivera_1)\
**Post date:** [April 27, 2015, 8:42pm UTC](https://forums.unrealengine.com/t/have-a-turret-rotate-towards-crosshair/316480/11 "2015-04-27T20:42:44Z")

</div>

finally got it 🙂 piece a cake at the end! You don’t need all these exessive nodes.

1)aim

 ![40461-final_turret_aim.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/0/f/80f6361e72be6b4701ef8134cb38e3f548146085.jpeg)

2)bp

 ![40463-final_turret_bp.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/8/7/d8747e52c3fb92c896d9478fa1ab264797686853.jpeg)

Please consider to be more specific from the start next time 🙂  
Good luck!

---

<div class="post-metadata">

**Author:** ![Taurian](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Taurian](https://forums.unrealengine.com/u/Taurian)\
**Post date:** [April 27, 2015, 8:44pm UTC](https://forums.unrealengine.com/t/have-a-turret-rotate-towards-crosshair/316480/12 "2015-04-27T20:44:26Z")

</div>

Here’s the solution.

 ![40455-capture.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/6/1/36183d360d2e2579d9688824883cfb06479711d5.png)
