Have a turret rotate towards crosshair?

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

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:

Hope that helps.

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:

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)

2)turrent blueprint tick function

  1. the result

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)

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?

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

Good luck with your project.

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

I’ll keep trying.

Now looking at cursor crosshair (pretty good):

and corresponding blueprint:

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

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

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

1)aim

2)bp

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

Here’s the solution.