Hi,
I’ve been following this tutorial series here:
http://cgcookie.com/unity/lessons/2-sam-turret/
I have a Turret model that will use this code :
function Update ()
{
if (myTarget)
{
aim_Pan.LookAt(myTarget);
aim_Pan.eulerAngles = Vector3(0, aim_Pan.eulerAngles.y, 0);
aim_Tilt.LookAt(myTarget);
pivot_Pan.rotation = Quaternion.Lerp(pivot_Pan.rotation, aim_Pan.rotation, Time.deltaTime * turnSpeed);
pivot_Tilt.rotation = Quaternion.Lerp(pivot_Tilt.rotation, aim_Tilt.rotation, Time.deltaTime * turnSpeed);
if(Time.time >= nextFireTime)
{
FireProjectile();
}
}
}
and make my model look at the enemy, it works for the most part but the problem is its 90 Degrees off target. So it will look at the target but be off, it still follows it around but its always 90 degrees off target.
I’ve also tried this code to try and fix
function Update ()
{
if (myTarget)
{
CalculateAimPosition(myTarget.position);
aim_Pan.rotation = Quaternion.Lerp(aim_Pan.rotation, desiredRotation, Time.deltaTime * turnSpeed);
aim_Tilt.LookAt(myTarget);
pivot_Pan.rotation = Quaternion.Lerp(pivot_Pan.rotation, aim_Pan.rotation, Time.deltaTime * turnSpeed);
pivot_Tilt.rotation = Quaternion.Lerp(pivot_Tilt.rotation, aim_Tilt.rotation, Time.deltaTime * turnSpeed);
if(Time.time >= nextFireTime)
{
FireProjectile();
}
}
}
//Calculates what we need to do to aim at the target
function CalculateAimPosition (targetPos : Vector3)
{
//Temp var, so we know where we are aiming, add aiming error to it
var aimPoint = Vector3(targetPos.x, targetPos.y, targetPos.z);
//set our desired rotation to the aimpoint, aim where we want to aim
desiredRotation = Quaternion.LookRotation(aimPoint - aim_Pan.position);
}
But it still has the same problem.
I’ve also tried editing the model file. I’ve rotated the model in Maya but still the problem persists.
Any idea’s?