Good afternoon good people of Unity3D!
Today I have a small issue that i’ve been meaning to fix for a while - my partner keeps telling me that the effects of my programming look half-assed
So I ask of you good folk, how can I limit the angles at which a turret can aim? At the moment I’m using a script similar to that in the tornadotwins’ tutorials to control a turret which has a texture (an arm and gun) attached to it - when the saucer is overhead this looks slightly strange because this poor man’s shoulders are protruding from his stomach. Here is the original script;
var LookAtTarget : Transform;
var damp = 1.0;
var bulletPrefab : Transform;
var thingdelay : int;
var cowxpos : float;
var cowypos : float;
function secondwait ()
{
thingdelay = 1;
yield WaitForSeconds(2);
thingdelay = 0;
}
function Update ()
{
LookAtTarget2 = transform.Find("front");
cowxpos = transform.position.x;
cowypos = transform.position.y;
if (cowxpos >= UFOcontrolBox.ufoxpos + 0.5)
{
Shoot();
if(LookAtTarget)
{
var rotate = Quaternion.LookRotation(LookAtTarget.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * damp);
}
}
if (cowxpos <= UFOcontrolBox.ufoxpos - 0.5)
{
Shoot();
if(LookAtTarget)
{
rotate = Quaternion.LookRotation(LookAtTarget.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * damp);
}
}
}
function Shoot()
{
if (thingdelay == 0)
{
var bullet = Instantiate(bulletPrefab, transform.Find("spawnPoint").transform.position, Quaternion.identity);
bullet.gameObject.tag = "enemyProjectile";
bullet.rigidbody.AddForce(transform.forward * 350);
secondwait();
}
}
This is the control script for the gun - thanks in advance everybody!