# Turret Issues

**URL:** https://discussions.unity.com/t/turret-issues/422761
**Category:** Scripting
**Tags:** Scripting
**Created:** [September 10, 2010, 10:59pm UTC](https://discussions.unity.com/t/turret-issues/422761 "2010-09-10T22:59:28Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![TylerCode](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/tylercode/32/568131_2.png) [@TylerCode](https://discussions.unity.com/u/TylerCode)
#### Post date: [September 10, 2010, 10:59pm UTC](https://discussions.unity.com/t/turret-issues/422761/1 "2010-09-10T22:59:28Z")

</div>

# No matter what I try, it won’t shoot properly, I’ve tried the tornadoTwins tutorial but I just get errors. I’ve been working on this for about 3-4 hours and I just can’t get it. I’ve tried making the Projectile object itself shoot forward, but then, it always goes along World X. and I’ve tried doing so in the turret script, but then the projectile just falls to the ground -.- . heres my script for the turret. (I’d continue troubleshooting myself, but I’m fairly new to scripting (Took a C++ class in HS but thats about it). besides I have set myself a schedule and do not wish to get behind.)

=============================================

```auto
var LookAtTarget : Transform;
var damp = 5.0;
var fireBall : Transform;
var savedTime = 0;

function Update()

{
	if(LookAtTarget)
	{
		var rotate = Quaternion.LookRotation(LookAtTarget.position - transform.position);
		
		transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * damp);
	//transform.LookAt(LookAtTarget);
	
		var seconds : int = Time.time;
		var oddeven = (seconds % 2);
		
		if(oddeven)
		{
		Shoot(seconds);
		}
	}
}

function Shoot(seconds)
{
	if(seconds!=savedTime)
	{
		Instantiate(fireBall ,transform.Find("spawnPoint2").transform.position ,Quaternion.identity);
		fireBall.rigidbody.AddForce(transform.forward * 1000);
		savedTime=seconds;
	}
										
}

```

# ========================================

---

<div class="post-metadata">

### Author: ![j\_y\_k](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@j\_y\_k](https://discussions.unity.com/u/j_y_k)
#### Post date: [September 10, 2010, 11:11pm UTC](https://discussions.unity.com/t/turret-issues/422761/2 "2010-09-10T23:11:27Z")

</div>

Regarding the ‘falling to the ground’ part, have you tried disabling gravity for the rigid body in question? (Also, if your intention with the AddForce() call is to give the projectile an initial velocity, be sure to submit ForceMode.Impulse for the ‘mode’ argument.)

---

<div class="post-metadata">

### Author: ![TylerCode](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/tylercode/32/568131_2.png) [@TylerCode](https://discussions.unity.com/u/TylerCode)
#### Post date: [September 10, 2010, 11:21pm UTC](https://discussions.unity.com/t/turret-issues/422761/3 "2010-09-10T23:21:56Z")

</div>

Thanks, but I got it to work, I’ll post the code to help anyone else in the future.

```auto
var LookAtTarget : Transform;
var damp = 5.0;
var fireBall : Transform;
var savedTime = 0;
//Should have made Side-notes while I wrote/modified this
function Update()

{
	if(LookAtTarget)
	{
		var rotate = Quaternion.LookRotation(LookAtTarget.position - transform.position);
		
		transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * damp);
	//transform.LookAt(LookAtTarget);
	
		var seconds : int = Time.time;
		var oddeven = (seconds % 2);
		
		if(oddeven)
		{
		Shoot(seconds);
		}
	}
}
//This here causes the Projectile to fire
function Shoot(seconds)
{
	if(seconds!=savedTime)
	{
		var bullet = Instantiate(fireBall ,transform.Find("spawnPoint2").transform.position ,Quaternion.identity);

//Forces Forward Motion upon fireBall bullet.rigidbody.AddForce(transform.forward * 1000);
		savedTime=seconds;
	}
										
}

```

Thanks again though for the quick response.
