Avatar
Welcome, Guest

Topic: Locked On Missile

Posts: 3 Likes: 0

OFFLINE

I am using 5.5.3 and I am trying to write a code for a homing missile, and I am using transform.lookat(), and moving it in Z Direction, is there any better way of doing it?

Posted : 3 weeks 2 days ago top

Posts: 4 Likes: 0

OFFLINE

Hi Kshitij,
Homing missiles will generally lock on to a target and keep following it OR the missile might auto-destroy after a certain period of time without hitting target.procedure is as follows :

--> We can controlled speed of the projectile in Update() function using speed variable :
transform.Translate(0,0,speed * Time.deltaTime,Space.Self);

--> Self-destructs after a set amount of time :
Void Start ()
{
StartCoroutine(SelfExplode());
}

void SelfExplode() {
yield return new WaitForSeconds(autoDestroyAfter);
Explode();
}
void Explode()
{
Instantiate(explosion,transform.position,Quaternion.identity);
Destroy(gameObject);
}

--> The Homing missiles needs to follow the target :

Vector3 relativePos = target.position - transform.position;
Quaternion rotation = Quaternion.LookRotation(relativePos);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, homingSensitivity);

Hope this will help you.

Posted : 3 weeks 2 days ago top

2 Item(s)

per page
Copyright 2017, GameGorillaz.
Game Gorillaz name and logo is registered trademark of Miracle Studios Pvt Ltd.