Here’s what I have so far. I really like the behaiour of the missle taking a “wide arc” to get to it’s target. However, I am currently stumped as to how to have the missle not fall into an “orbit” around the target if the target is close enough to the launcher.
My main issue is I’m trying to use Vector3.Distance value somehow, as I’m trying to increase the damping value to make the missile more accurate based on proximity. But Distance obvious increases as the object is far away, and decreases as it get’s closer.
ex; if the target happens to be beside the launcher, their should be no arc, but if it is further away, then we should see the slerp
So somehow, I need to invert the value given to me by Distance.
Any thoughts?
Here’s the code so far;
#pragma strict
var target : Transform;
var damping: float = 1.0;
var speed: float = 15;
var dist: float = 0.0;
var altDist: float = 0.0;
function Update ()
{
transform.Translate(Vector3.forward * Time.deltaTime * speed);
var rotation = Quaternion.LookRotation(target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
// if (target)
// {
// dist = Vector3.Distance(target.position, transform.position);
// altDist = dist / 100 + 1;
// }
//
}
function OnTriggerEnter ( other : Collider )
{
if (other.gameObject.tag == "alien")
{
print ("hit");
}
}
(ignore my commented out sections…I was just fidgeting trying different things…)