- Home /
Turret won't shoot
I have a turret that looks at the player and is supposed to shoot a ParticleSystem at the player. It looks at the player just fine, but even out of the safe distance I have setup it will not trigger the ParticleSystem. Here is my script:
var findTarget : Transform ;
var lookAtDistance = 20;
var safeDistance = 15;
var fireDelay : float;
var prefab : ParticleSystem;
function Update(){
var distanceToPlayer = Vector3.Distance(this.transform.position, findTarget .transform.position);
transform.LookAt(findTarget);
if( Input.GetKeyDown( KeyCode.Space ) ) {
Fire();
}
}
function Fire() {
Debug.Log("Fire away!");
var clone : ParticleSystem;
clone = Instantiate(prefab, transform.position, transform.rotation) as ParticleSystem;
}
I also need some help adding the ability to take away health points upon contact with the ParticleSystem and player. I'm focusing on the shooting aspect for now but I will need to take damage when that is all ready and done.
//Change this
if( Input.Get$$anonymous$$eyDown( $$anonymous$$eyCode.Space ) ) {
Fire();
}
//To this
if( distanceToPlayer <= safeDistance ) {
Fire();
}
In your previous question, I put in the Input.Get$$anonymous$$eyDown( $$anonymous$$eyCode.Space )
for quick-debugging purposes by skipping the check distance.
On top of what Chronos-L said, is your prefab object containing a rigidbody?
the prefab is a particle system, can you make particle systems have rigidbody?
after changing it back to
if( distanceToPlayer <= safeDistance ) { Fire(); }
the particle system still does not fire.
Do you have the "Fire away!" message in your console? Or do you have any error messages?
ahhh it works !!! lol ok cool thanks Chonos i'll go from here
btw if you convert that last comment into a answer i'll call it a day for this Question :D thanks for all your help
Answer by Chronos-L · Apr 15, 2013 at 12:38 AM
This is the one that works in my PC. There are no major difference with yours except that mine is a stripped down version. You can give this a shot.
#pragma strict
var prefab : ParticleSystem;
function Update(){
if( Input.GetKeyDown( KeyCode.Space ) ) {
Fire();
}
}
function Fire() {
Debug.Log("Fire away!");
var clone : ParticleSystem;
clone = Instantiate(prefab, transform.position, transform.rotation) as ParticleSystem;
}