Hi guys - I’m making a tower defence game, yet I’ve come across a problem.
I have a Trigger Sphere Collider on my turrent, and when the enemy object comes in range, the tower follows and shoots. However, for some reason, the tower rotates in the X axis, which shouldn’t happen - it should only rotate on the Y.
Any clues?
function Update() {
if (myTarget) {
if (Time.time >= nextMoveTime) {
CalculateAimPosition(myTarget.position);
turretBall.rotation = Quaternion.Lerp(turretBall.rotation, desiredRotation, Time.deltaTime * turnSpeed);
}
if (Time.time >= nextFireTime) {
FireProjectile();
}
}
}
function CalculateAimPosition(targetPos : Vector3) {
var aimPoint = Vector3(targetPos.x + aimError, targetPos.y + aimError, targetPos.z + aimError);
desiredRotation = Quaternion.LookRotation(aimPoint);
}
function CalculateAimError() {
aimError = Random.Range(-errorAmount, errorAmount);
}