I have two missile creators, but as they all have the same trajectory, they end up looking like one because they don't collide. i have a follow script here. I was wondering what i should do (& how) to make them collide & fly side by side, or bounce off each other, but it is troublesome if they are in the same place. this also happens with my enemies which have a follow script like this one. Please help!!!
public class ExperimentalRocketGrenade : MonoBehaviour {
public GameObject Explosion;
public ExperimentalDeath ScriptedObjectScript;
public float Health = 30;
public GameObject Target;
public GameObject ScriptedObject;
public float BulletSpeed;
public Transform TargetGo;
public bool isDead;
public bool isNearObject;
public Transform _myTransform;
public float damping;
public float Counter;
public float PlayeDamage;
public float LifeTime;
//Use this for who knows what
void Awake () {
_myTransform = transform;
}
// Use this for initialization
void Start () {
isNearObject = false;
Target = GameObject.Find("Bandana");
ScriptedObject = GameObject.Find("MonstercatChar");
ScriptedObjectScript = ScriptedObject.GetComponent ();
TargetGo = Target.transform;
}
void LateUpdate () {
Quaternion rotation = Quaternion.LookRotation(TargetGo.position - _myTransform.position);
_myTransform.rotation = Quaternion.Slerp(_myTransform.rotation, rotation, Time.deltaTime * damping);
}
// Update is called once per frame
void Update () {
Counter += 1;
if(Counter > LifeTime){
EnemyDie();
}
if (BulletSpeed < 400) {
BulletSpeed += 0.25f;
}
if (damping < 10){
damping += 0.02f;
}
if (isNearObject == true) {
//Debug.Log ("Is in range");
}
if (Health < 0.1) {
isDead = true;
EnemyDie ();
}
GameObject Char = GameObject.Find("MonstercatChar");
transform.position += transform.forward * BulletSpeed * Time.deltaTime;
if(Vector3.Distance(TargetGo.position, transform.position) < 5) {
//Debug.Log ("Is Damaging " + Char);
}
}
public void EnemyDamage (float amount) {
Health -= amount;
}
void OnTriggerEnter(Collider other) {
isNearObject = true;
if(other.gameObject == GameObject.Find("MonstercatChar")){
Instantiate(Explosion, transform.position, transform.rotation);
Destroy (gameObject, 0);
ScriptedObjectScript.DamageChar(PlayeDamage);
}
if(other.gameObject == GameObject.FindGameObjectWithTag("PlayerBullet")){
EnemyDamage(Random.Range(2,3));
Debug.Log ("Rocket Damaged");
}
if(other.gameObject == GameObject.FindGameObjectWithTag("EnemyRocket")){
Debug.Log ("Rocket collided rocket");
}
isNearObject = true;
}
void OnTriggerExit (Collider other) {
isNearObject = false;
}
void EnemyDie () {
Instantiate(Explosion, transform.position, transform.rotation);
Destroy (gameObject, 0);
}
}
↧