How do I make a turret that aims and shoots at an object that is moving?

How do i make a turret that aims and shoots at the player or another object that is moving?? im sure this stuff has been covered just cant find the info. thx

You first have to select a target depending on your AI logic. Do this within the AIController. Once a target is chosen, store a reference to it in CurrentTarget. Now within the tick function, calculate a vector towards the target :

vec = GetPawn()->GetActorLocation() - CurrentTarget->GetActorLocation()

Now set your pawn’s rotation to vec (you must convert it to a Rotator first)

Hi ,

The best approach would be to deconstruct the BP_Security_Camera_Tracking asset from the BlueprintExamples project. You can break down the movement of the parts in the same way that a turret would move and track the player, but change the Alarm state to a firing state. You can fire bullets by using a Spawn Actor from Class node.

I hope that this helps you with your blueprint. Let us know if you need further assistance.

Hello ,

For turret, I found this series of tutorial very helpful:
https://www.youtube.com/watch?v=XXGWjaRs4zs

Worked like a charm for me.

Hi here is another good tutorial www.vaduunlabs.com/index.php/en/tutorials/29-adv-turret-animation.

With the help of this tutorial, you will be able to animate turrets in UE4, which are always tracking the target correctly, regardless of their own orientation.

I found this tutorial to be very helpful in this matter. http://shootertutorial.com/2015/08/28/turret-tutorial/

To convert vev to a rotator, normalize vec and call RotatorFromXVector in blueprints. With the above direction and rotator you can spawn your projectile and rotste the turret mesh into the correct orientation.