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.GetKeyDown( KeyCode.Space ) ) { Fire(); } //To this if( distanceToPlayer <= safeDistance ) { Fire(); } In your previous question, I put in the
– Chronos-LInput.GetKeyDown( KeyCode.Space )for quick-debugging purposes by skipping the check distance.On top of what Chronos-L said, is your prefab object containing a rigidbody?
– Negagamesthe 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.
– RickHurdDo you have the "Fire away!" message in your console? Or do you have any error messages?
– Chronos-Lno that message does not come up, and no errors regarding the turret.
– RickHurd