hi
ive been looking everywhere online for some help with coding a homing missile in unity
can any one help and tell me where i am going wrong
public Rigidbody projectile;
public float speed = 10.0f;
Public Transform target;
void Update() {
if (Input.GetButtonDown("Fire1")) {
Rigidbody clone;
clone = Instantiate(projectile, transform.position, transform.rotation) as Rigidbody;
clone.transform.LookAt(target);
clone.velocity = transform.TransformDirection(Vector3.forward * speed);
Destroy(clone.gameObject,5.0f);
}
}
void OnCollisionEnter(Collision collision){
Destroy(clone.gameObject);
}
the code used to just shoot the projectile in front of the character and would bounce off the walls and then after 5 seconds it would be destroyed
after i tried implementing destroying the object when ever it collides with something and trying to make it go towards the given target it doesn’t even move now
can i please get some help I’ve tried looking online for tutorials but they are all in java and I’ve tried converting the code to c# but it doesn’t work
enter code here