- Home /
How to make a turret focus on a point?
Hi there,
I have followed a tutorial online to have a turret following my characters position and shooting in that direct, however fro some reason my stock characters "focal" point is pretty misaligned? I have tried using the character head as a target for the turret, however it refuses to even move in that case. I have tried adding an empty gameObject as a child of my character and using that as the target but again no luck with the turret giving any reaction. You can see from my screenshot below how the turret works: ![Facing into the ground][1] (as a side note, my player is also slanted for some reason?
Here is the code I am using for the turret movement:
var target : Transform;
var turret : Transform;
var damp = 1.0;
var bullet : Transform;
var bulletSpawn : Transform;
var timer = 0.0;
function OnTriggerStay (other : Collider)
{
timer+= Time.deltaTime;
if (other.transform == target)
{
turret.transform.LookAt(target);
if (timer>0.5)
{
Instantiate(bullet, bulletSpawn.position, bulletSpawn.rotation);
timer = 0.0;
}
}
}
Many thanks! [1]: /storage/temp/24121-screen+shot+2014-03-23+at+16.47.10.png
Answer by SkaredCreations · Mar 23, 2014 at 06:11 PM
Your turret source model is probably not aligned with Unity directions (that are Y-up, Z-forward), set the rotation of your turret to 0,0,0 in the scene editor and see if it's facing forward (Z-positive direction) correctly: if it's not then you can just parent the turret to a gameobject with rotation 0,0,0 and align the turret transform rotation to face forward (or fix the rotation of the source model in your 3D software). About your player rotation you're most likely rotating it in X/Z instead of only Y in your scripts.
Your answer
![](https://koobas.hobune.stream/wayback/20220613141001im_/https://answers.unity.com/themes/thub/images/avi.jpg)