# Why is my turret firing in the wrong direction?

Hi, I’m learning how to use Unity still and I have a question about the game I’m making. I’m following this tutorial, CG Cookie | Learn Blender, Online Tutorials and Help - CG Cookie | Learn Blender, Online Tutorials and Feedback, because I want to make a Tower Defense game. I have the code exactly like they have it but my turret is not firing in the right direction. I think this means that my tower is rotated the wrong way or there is something wrong with my turret. I’ll post my code in case I did make a silly error but I think it should be right. If anyone could shed some light on this situation that would be great!
#pragma strict

``````var myProjectile : GameObject;
var reloadTime : float = 1f;
var firePauseTime : float = .25f;
var turnSpeed : float = 5f;
var myTarget : Transform;
var muzzlePosition : Transform;
var turretBall : Transform;

private var nextFireTime : float;
private var nextMoveTime : float;
private var desiredRotation : Quaternion;

function Update ()
{

if(myTarget)
{
if (Time.time >= nextMoveTime)
{
CalculateAimPosition(myTarget.position);
var myRotation = turretBall.rotation;
turretBall.rotation = Quaternion.Lerp(myRotation, desiredRotation, Time.deltaTime*turnSpeed);

}
if (Time.time >= nextFireTime)
{
FireProjectile();
}
}
}

function OnTriggerEnter(other : Collider)
{

if (other.gameObject.tag == "Enemy")
{
myTarget = other.gameObject.transform;
nextFireTime = Time.time + (reloadTime * .5);
}
}

function OnTriggerExit(other : Collider)
{
myTarget = null;
}
function CalculateAimPosition(targetPos : Vector3)
{
var aimPoint = Vector3(targetPos.x,targetPos.y, targetPos.z);
desiredRotation = Quaternion.LookRotation(aimPoint);
Debug.Log("Aim Point: " + aimPoint);
Debug.Log("Desired Rotation: " + desiredRotation);
}
function FireProjectile()
{
nextMoveTime = Time.time + firePauseTime;
Instantiate(myProjectile, muzzlePosition.position, muzzlePosition.rotation);
}
``````

Ah I had the exact same problem following that tut, and believe me you’re gonna have a lot more. xD

I really suggest doing the Lunar Lander series first cause there’s only 7 parts and I had no problems up to part 5 and then I ran into a speed bump, posted a Q about it here.

Anyway, unfortunately I don’t remember how I solved it exactly and UnityCookie changed their website I guess and all the previous comments with the same problems and solutions (including mine) are gone.

I can tell you tho that this tut will heavily depend on the way your models are positioned in the modeling program and the axis coordinates they are exported under.

If I remember correctly I had that problem cause first time I just made the basic turret model within Unity and that caused it. I’m stuck on part 7 of the tutorial unfortunately tho. A speed bump I didn’t manage to solve, yet. xD

Also for other, or that one too, rotation problems if you’re using Blender like me in most cases the object has to be “on its back” and exported as .fbx with Z as forward and Y as up, because Blender has different world coordinates. Depends how you position it initially.

Hope some of those tips helped. You can PM me if you have more Qs about the tut. Good luck. :S