nokilling rocket help

i’v bean working on the fps the unity has on thare site. in it you get to make rockets but thay don’t kill. how do i make them kill? here is my code for the rocket and the throwing kinfe. :shock:

rocket lancher :!:

var projectile : Rigidbody;
var initialSpeed = 20.0;
var reloadTime = 0.5;
var ammoCount = 20;
private var lastShot = -10.0;

function Fire () {
	// Did the time exceed the reload time?
	if (Time.time > reloadTime + lastShot  ammoCount > 0) {
		// create a new projectile, use the same position and rotation as the Launcher.
		var instantiatedProjectile : Rigidbody = Instantiate (projectile, transform.position, transform.rotation);
			
		// Give it an initial forward velocity. The direction is along the z-axis of the missile launcher's transform.
		instantiatedProjectile.velocity = transform.TransformDirection(Vector3 (0, 0, initialSpeed));

		// Ignore collisions between the missile and the character controller
		Physics.IgnoreCollision(instantiatedProjectile.collider, transform.root.collider);
		
		lastShot = Time.time;
		ammoCount--;
	}
}


and here is my rocket :) 


[code]
// The reference to the explosion prefab
var explosion : GameObject;
var timeOut = 3.0;

// Kill the rocket after a while automatically
function Start () {
	Invoke("Kill", timeOut);
}


function OnCollisionEnter (collision : Collision) {
	// Instantiate explosion at the impact point and rotate the explosion
	// so that the y-axis faces along the surface normal
	var contact : ContactPoint = collision.contacts[0];
	var rotation = Quaternion.FromToRotation(Vector3.up, contact.normal);
    Instantiate (explosion, contact.point, rotation);

	// And kill our selves
	Kill ();    
}

function Kill () {
	// Stop emitting particles in any children
	var emitter : ParticleEmitter= GetComponentInChildren(ParticleEmitter);
	if (emitter)
		emitter.emit = false;

	// Detach children - We do this to detach the trail rendererer which should be set up to auto destruct
	transform.DetachChildren();
		
	// Destroy the projectile
	Destroy(gameObject);
}


@script RequireComponent (Rigidbody)
[b]
[/b]

var kinfeanim : GameObject;
is my throw the kinfe animation. :slight_smile:

var projectile : Rigidbody;
is the kinfe

var projectile : Rigidbody;
var kinfeanim : GameObject;
var initialSpeed = 20.0;
var reloadTime = 3;
var ammoCount = 2;
private var lastShot = -10.0;

function Fire () {
	// Did the time exceed the reload time?
	if (Time.time > reloadTime + lastShot  ammoCount > 0) {
		// create a new projectile, use the same position and rotation as the Launcher.
		kinfeanim.animation.CrossFadeQueued("throwkinfe", 0.3, QueueMode.PlayNow);
		var instantiatedProjectile : Rigidbody = Instantiate (projectile, transform.position, transform.rotation);
			
		// Give it an initial forward velocity. The direction is along the z-axis of the missile launcher's transform.
		instantiatedProjectile.velocity = transform.TransformDirection(Vector3 (0, 0, initialSpeed));

		// Ignore collisions between the missile and the character controller
		Physics.IgnoreCollision(instantiatedProjectile.collider, transform.root.collider);
		
		lastShot = Time.time;
		ammoCount--;
	}
}

var KnifeEffect : GameObject;
is a puf of dust.
and yes i use the rocket sctipt but i did modify it.
i wold like it if the kinfe was replced be a prefab kinfe that wold stick into things whene the rail one hit something. :smile:

// The reference to the explosion prefab
var KnifeEffect : GameObject;
var timeOut = 5.0;

// Kill the rocket after a while automatically
function Start () {
	Invoke("Kill", timeOut);
}


function OnCollisionEnter (collision : Collision) {
	// Instantiate explosion at the impact point and rotate the explosion
	// so that the y-axis faces along the surface normal
	var contact : ContactPoint = collision.contacts[0];
	var rotation = Quaternion.FromToRotation(Vector3.up, contact.normal);
    Instantiate (KnifeEffect, contact.point, rotation);

	// And kill our selves
	Kill ();    
}

function Kill () {
	// Stop emitting particles in any children
	var emitter : ParticleEmitter= GetComponentInChildren(ParticleEmitter);
	if (emitter)
		emitter.emit = false;

	// Detach children - We do this to detach the trail rendererer which should be set up to auto destruct
	transform.DetachChildren();
		
	// Destroy the projectile
	Destroy(gameObject);
}

so if you can help pleese do. :smile:

Do you mean you want the rocket to damage objects it hits or you want it to disappear after it has hit something?

i want it to hirt this ai and me to if it hits me

AI

var hitPoints = 100.0;
var deadReplacement : Transform;
var dieSound : AudioClip;

function ApplyDamage (damage : float) {
	// We already have less than 0 hitpoints, maybe we got killed already?
	if (hitPoints <= 0.0)
		return;

	hitPoints -= damage;
	if (hitPoints <= 0.0)
	{
		Detonate();
	}
}

function Detonate () {
	// Destroy ourselves
	Destroy(gameObject);
	
	// Play a dying audio clip
	if (dieSound)
		AudioSource.PlayClipAtPoint(dieSound, transform.position);

	// Replace ourselves with the dead body
	if (deadReplacement) {
		var dead : Transform = Instantiate(deadReplacement, transform.position, transform.rotation);
		
		// Copy position  rotation from the old hierarchy into the dead replacement
		CopyTransformsRecurse(transform, dead);
	}
}

static function CopyTransformsRecurse (src : Transform,  dst : Transform) {
	dst.position = src.position;
	dst.rotation = src.rotation;
	
	for (var child : Transform in dst) {
		// Match the transform with the same name
		var curSrc = src.Find(child.name);
		if (curSrc)
			CopyTransformsRecurse(curSrc, child);
	}
}

and player

var maximumHitPoints = 100.0;
var hitPoints = 100.0;

var bulletGUI : GUIText;
var rocketGUI : DrawRockets;
var healthGUI : GUITexture;

var slideclip : AudioClip[];
var range = 100.0;
var audioslideLength = 0.3;
var slideing = false;
var walking = false;
var hitsomthig = false;

var walkSounds : AudioClip[];
var painLittle : AudioClip;
var painBig : AudioClip;
var die : AudioClip;
var audioStepLength = 0.3;

private var machineGun : MachineGun;
private var rocketLauncher : RocketLauncher;
private var healthGUIWidth = 0.0;
private var gotHitTimer = -1.0;

var rocketTextures : Texture[];

function soundtoplay() {
		var direction = transform.TransformDirection(-Vector3.up);
		var hit2 : RaycastHit;
		if (Physics.Raycast (transform.position, direction, hit2, range)) {
        hitsomthig = true;
	
			 //yield WaitForSeconds(audio.clip.length);
			
		}
		if (hit2.collider.tag == "Slide") {
		walking = false;
		slideing = true;
		}
	}





function Awake () {
	machineGun = GetComponentInChildren(MachineGun);
	rocketLauncher = GetComponentInChildren(RocketLauncher);

	PlayStepSounds();

	healthGUIWidth = healthGUI.pixelInset.width;
}

function ApplyDamage (damage : float) {
	if (hitPoints < 0.0)
		return;

	// Apply damage
	hitPoints -= damage;

	// Play pain sound when getting hit - but don't play so often
	if (Time.time > gotHitTimer  painBig  painLittle) {
		// Play a big pain sound
		if (hitPoints < maximumHitPoints * 0.2 || damage > 20) {
			audio.PlayOneShot(painBig, 1.0 / audio.volume);
			gotHitTimer = Time.time + Random.Range(painBig.length * 2, painBig.length * 3);
		} else {
			// Play a small pain sound
			audio.PlayOneShot(painLittle, 1.0 / audio.volume);
			gotHitTimer = Time.time + Random.Range(painLittle.length * 2, painLittle.length * 3);
		}
	}

	// Are we dead?
	if (hitPoints < 0.0)
		Die();
}

    

function Die () {
	if (die)
		AudioSource.PlayClipAtPoint(die, transform.position);
	
	// Disable all script behaviours (Essentially deactivating player control)
	var coms : Component[] = GetComponentsInChildren(MonoBehaviour);
	for (var b in coms) {
		var p : MonoBehaviour = b as MonoBehaviour;
		if (p)
			p.enabled = false;
	}

	LevelLoadFade.FadeAndLoadLevel(Application.loadedLevel, Color.white, 2.0);
}

function LateUpdate () {
	// Update gui every frame
	// We do this in late update to make sure machine guns etc. were already executed
	UpdateGUI();
}

function PlayStepSounds () {
soundtoplay();
	var controller : CharacterController = GetComponent(CharacterController);

	while (true) {
		if (controller.isGrounded  controller.velocity.magnitude > 0.3  walking  !slideing) {
			audio.clip = walkSounds[Random.Range(0, walkSounds.length)];
			audio.Play();
			yield WaitForSeconds(audioStepLength);
			slideing = false;
		} else if (slideing) {
			walking = false;
			audio.clip = slideclip[Random.Range(0, slideclip.length)];
			audio.Play();
			yield WaitForSeconds(audioslideLength);
		
		
		
		
		 } else {
			yield;
		}
	}
}


function UpdateGUI () {
	// Update health gui
	// The health gui is rendered using a overlay texture which is scaled down based on health
	// - Calculate fraction of how much health we have left (0...1)
	var healthFraction = Mathf.Clamp01(hitPoints / maximumHitPoints);

	// - Adjust maximum pixel inset based on it
	healthGUI.pixelInset.xMax = healthGUI.pixelInset.xMin + healthGUIWidth * healthFraction;

	// Update machine gun gui
	// Machine gun gui is simply drawn with a bullet counter text
	if (machineGun) {
		bulletGUI.text = machineGun.GetBulletsLeft().ToString();
	}
	
	// Update rocket gui
	// This is changed from the tutorial PDF. You need to assign the 20 Rocket textures found in the GUI/Rockets folder
	// to the RocketTextures property.
	if (rocketLauncher)	{
		rocketGUI.UpdateRockets(rocketLauncher.ammoCount);
		/*if (rocketTextures.Length == 0) {
			Debug.LogError ("The tutorial was changed with Unity 2.0 - You need to assign the 20 Rocket textures found in the GUI/Rockets folder to the RocketTextures property.");
		} else {
			rocketGUI.texture = rocketTextures[rocketLauncher.ammoCount];
		}*/
	}
}

i want it to hirt this ai and me to if it hits me

AI

var hitPoints = 100.0;
var deadReplacement : Transform;
var dieSound : AudioClip;

function ApplyDamage (damage : float) {
	// We already have less than 0 hitpoints, maybe we got killed already?
	if (hitPoints <= 0.0)
		return;

	hitPoints -= damage;
	if (hitPoints <= 0.0)
	{
		Detonate();
	}
}

function Detonate () {
	// Destroy ourselves
	Destroy(gameObject);
	
	// Play a dying audio clip
	if (dieSound)
		AudioSource.PlayClipAtPoint(dieSound, transform.position);

	// Replace ourselves with the dead body
	if (deadReplacement) {
		var dead : Transform = Instantiate(deadReplacement, transform.position, transform.rotation);
		
		// Copy position  rotation from the old hierarchy into the dead replacement
		CopyTransformsRecurse(transform, dead);
	}
}

static function CopyTransformsRecurse (src : Transform,  dst : Transform) {
	dst.position = src.position;
	dst.rotation = src.rotation;
	
	for (var child : Transform in dst) {
		// Match the transform with the same name
		var curSrc = src.Find(child.name);
		if (curSrc)
			CopyTransformsRecurse(curSrc, child);
	}
}

and player

var maximumHitPoints = 100.0;
var hitPoints = 100.0;

var bulletGUI : GUIText;
var rocketGUI : DrawRockets;
var healthGUI : GUITexture;

var slideclip : AudioClip[];
var range = 100.0;
var audioslideLength = 0.3;
var slideing = false;
var walking = false;
var hitsomthig = false;

var walkSounds : AudioClip[];
var painLittle : AudioClip;
var painBig : AudioClip;
var die : AudioClip;
var audioStepLength = 0.3;

private var machineGun : MachineGun;
private var rocketLauncher : RocketLauncher;
private var healthGUIWidth = 0.0;
private var gotHitTimer = -1.0;

var rocketTextures : Texture[];

function soundtoplay() {
		var direction = transform.TransformDirection(-Vector3.up);
		var hit2 : RaycastHit;
		if (Physics.Raycast (transform.position, direction, hit2, range)) {
        hitsomthig = true;
	
			 //yield WaitForSeconds(audio.clip.length);
			
		}
		if (hit2.collider.tag == "Slide") {
		walking = false;
		slideing = true;
		}
	}





function Awake () {
	machineGun = GetComponentInChildren(MachineGun);
	rocketLauncher = GetComponentInChildren(RocketLauncher);

	PlayStepSounds();

	healthGUIWidth = healthGUI.pixelInset.width;
}

function ApplyDamage (damage : float) {
	if (hitPoints < 0.0)
		return;

	// Apply damage
	hitPoints -= damage;

	// Play pain sound when getting hit - but don't play so often
	if (Time.time > gotHitTimer  painBig  painLittle) {
		// Play a big pain sound
		if (hitPoints < maximumHitPoints * 0.2 || damage > 20) {
			audio.PlayOneShot(painBig, 1.0 / audio.volume);
			gotHitTimer = Time.time + Random.Range(painBig.length * 2, painBig.length * 3);
		} else {
			// Play a small pain sound
			audio.PlayOneShot(painLittle, 1.0 / audio.volume);
			gotHitTimer = Time.time + Random.Range(painLittle.length * 2, painLittle.length * 3);
		}
	}

	// Are we dead?
	if (hitPoints < 0.0)
		Die();
}

    

function Die () {
	if (die)
		AudioSource.PlayClipAtPoint(die, transform.position);
	
	// Disable all script behaviours (Essentially deactivating player control)
	var coms : Component[] = GetComponentsInChildren(MonoBehaviour);
	for (var b in coms) {
		var p : MonoBehaviour = b as MonoBehaviour;
		if (p)
			p.enabled = false;
	}

	LevelLoadFade.FadeAndLoadLevel(Application.loadedLevel, Color.white, 2.0);
}

function LateUpdate () {
	// Update gui every frame
	// We do this in late update to make sure machine guns etc. were already executed
	UpdateGUI();
}

function PlayStepSounds () {
soundtoplay();
	var controller : CharacterController = GetComponent(CharacterController);

	while (true) {
		if (controller.isGrounded  controller.velocity.magnitude > 0.3  walking  !slideing) {
			audio.clip = walkSounds[Random.Range(0, walkSounds.length)];
			audio.Play();
			yield WaitForSeconds(audioStepLength);
			slideing = false;
		} else if (slideing) {
			walking = false;
			audio.clip = slideclip[Random.Range(0, slideclip.length)];
			audio.Play();
			yield WaitForSeconds(audioslideLength);
		
		
		
		
		 } else {
			yield;
		}
	}
}


function UpdateGUI () {
	// Update health gui
	// The health gui is rendered using a overlay texture which is scaled down based on health
	// - Calculate fraction of how much health we have left (0...1)
	var healthFraction = Mathf.Clamp01(hitPoints / maximumHitPoints);

	// - Adjust maximum pixel inset based on it
	healthGUI.pixelInset.xMax = healthGUI.pixelInset.xMin + healthGUIWidth * healthFraction;

	// Update machine gun gui
	// Machine gun gui is simply drawn with a bullet counter text
	if (machineGun) {
		bulletGUI.text = machineGun.GetBulletsLeft().ToString();
	}
	
	// Update rocket gui
	// This is changed from the tutorial PDF. You need to assign the 20 Rocket textures found in the GUI/Rockets folder
	// to the RocketTextures property.
	if (rocketLauncher)	{
		rocketGUI.UpdateRockets(rocketLauncher.ammoCount);
		/*if (rocketTextures.Length == 0) {
			Debug.LogError ("The tutorial was changed with Unity 2.0 - You need to assign the 20 Rocket textures found in the GUI/Rockets folder to the RocketTextures property.");
		} else {
			rocketGUI.texture = rocketTextures[rocketLauncher.ammoCount];
		}*/
	}
}