using UnityEngine;
using System.Collections;
//script only works if you have a tag named Player
//for best effect use a prefab
public class MissileScript : MonoBehaviour
{
public Transform target;
public float speed = 3f;
private bool ifTarget = false;
public void SetTarget(Transform helTrag)
{
target = helTrag;
ifTarget = true;
}
// Use this for initialization
void Start ()
{
SetTarget (target); //temp. call set target when intsintingings
}
void Update ()
{
if(ifTarget)
{
//roates the projectile this make it able for you to dodge the following projectile
Vector3 toTarget = target.position - transform.position;
Quaternion rotation = Quaternion.LookRotation(toTarget);
transform.rotation = Quaternion.RotateTowards(transform.rotation, rotation, Time.deltaTime*250f);
//lucnh the projectile fowards
GetComponent().velocity = transform.forward * speed;
//transform.rotation = new Quaternion(Mathf.LerpAngle(transform.rotation.x,
//transform.LookAt(toTarget);
//Vector3 toTarget = target.position - transform.position;
//GetComponent().velocity = toTarget.normalized * speed;
//transform.forward = toTarget.normalized;
}
}
}
this is my first post, dont be rude!