Here's a basic example of how to create a tracking turret in Unity:
First, create a new empty game object in the hierarchy and name it "Turret".
Add a 3D model of your turret to the Turret game object, and position it at the location where you want your turret to start.
Add a script to the Turret game object (or create a new script if you haven't already) in C#.
In the script, create a public variable for the target object (usually the player) and a public variable for the turret's rotation speed.
main.cs61 chars3 lines
Update()
function, get the direction from your turret to your target, and calculate the angle between the turret's forward vector and that direction.main.cs127 chars3 lines
Quaternion.LookRotation()
function to point your turret at the target.main.cs64 chars2 lines
Quaternion.Slerp()
to smoothly rotate your turret towards the target.main.cs107 chars2 lines
Now your turret will track the target object smoothly in 3D space!
gistlibby LogSnag