Ok i have a rocket launcher that shoots out a rocket… Thats not the problem it shoots fine. The rocket is suppose to collide with any objects in its path and explode… I have an imported terrain(because flash doesn’t allow you to use the unity’s terrain) that has a mesh collider. The rocket shot has a capsule collider. The rocket however collides with every other object except the Terrain… It collides occasionally but not very often and i want it to collide every time. Rocket Script:
using UnityEngine;
using System.Collections;
[RequireComponent (typeof (Rigidbody))]
public class RocketExplode : MonoBehaviour {
public int timeOut;
public GameObject explosion;
public GameObject character;
private Vector3 position;
void Start () {
timeOut = 3;
character = GameObject.FindWithTag("Player");
Invoke("Kill", timeOut);
Physics.IgnoreCollision(character.collider, collider);
}
void FixedUpdate()
{
if(transform.position != position)
{
if (Physics.Linecast (transform.position, position))
{
Instantiate(explosion,transform.position,transform.rotation);
Kill();
}
position = transform.position;
}
}
void OnCollisionEnter(Collision collision)
{
ContactPoint contact = collision.contacts[0];
Quaternion rotation = Quaternion.FromToRotation(Vector3.up, contact.normal);
Instantiate (explosion, contact.point, rotation);
Kill();
}
void Kill()
{
ParticleEmitter emitter = GetComponentInChildren<ParticleEmitter>();
if(emitter)
emitter.emit = false;
transform.DetachChildren();
Destroy(gameObject);
}
}
Also on top of that the rocket doesn’t destroy itself after it explodes… Any help is appreciated. Added in what syclamoth told me to do… did i do it wrong or something?