Restrict Pawn's Rotation

Hi all

I have a turret which automatically looks at the player and starts shooting. This functionality works well.

Now, I want to restrict the turret’s rotation capability so that it can’t rotate behind, it can’t look directly down etc.

What is the best way to go about this? Attached is a screenshot of my current Blueprint of the turret.

If any further information is required, please let me know.



Hi Cruisy.

Does the rotation look a little strange by any chance? It will work better if you get the current rotation before going into the timeline, rather than sampling it during.

Anyway… the clamp node is your friend. You can make sure the rotation values stay within certain bounds.

Have a look at this one:

Script to copy:

Image from Gyazo

Essentially, Dot Product is an answer to most angular issues. The yellow arrow indicates the turret’s front.

Oh, and a TL is probably not the way to go about it unless you’re after something truly specific / unique / inflexible. Does not mesh well with target tracking in my head.

Thanks Clockwork and Everynone. That Blueprint website is handy.

I have tried to implement it but I am still having issues, can you see what I am doing wrong?



EDIT: I think I actually figured it out. I have updated the Blueprint link above.

Please let me know if you see any issues.

You need to run this on Tick. If we want to see an update every frame (the animation), we need to interpolate every frame - that’s what the Timelines’ Update does as well. Interpolation relies on the data from the previous step.

Can’t recall how often Pawn sensing updates by default? Once a second, maybe twice. So you’d need to Sense the Pawn → Open the Gate for Tick so the script runs only when a Pawn is nearby - you could probably use the VisionRadius or whatshername.

Just to clarify:

Image from Gyazo

This is based on Distance from the Player but, ideally, should also incorporate the angle so the whole thing switches off (disable Tick, mayhap?) when the player is far away and outside of the vision cone. The vision cone is already calculated so you could leverage that.

But ofc, you may have a different idea as to when the turret’s target seeking script kicks in!

Hey that’s working really well, thanks!

i dont understand