bullet destroy on collison
after adding in the 'Destroy(gameObject);' line to destroy the bullet after colliding with a wall for example the enemy will not shoot. Any ideas as to why?
bullet script:
var Dammage = 50;
function OnCollisionEnter (info : Collision)
{
info.transform.SendMessage("ApplyDammage1", Dammage,
SendMessageOptions.DontRequireReceiver);
Destroy(gameObject);
}
function Update ()
{
var translation : float = Time.deltaTime * 60;
transform.Translate(0,0,translation);
}
ai script:
var Distance;
var Target : Transform;
var ShootRange = 25.0;
var attackRange = 15.0;
var moveSpeed = 5.0;
var Damping = 6.0;
var projectile : Rigidbody;
var fireRate : float = 1;
var FireRange = 0-100;
private var nextFire : float = 0.0;
function Update ()
{
Distance = Vector3.Distance(Target.position, transform.position);
if (Distance < ShootRange)
{
GetComponent.<Renderer>().material.color = Color.yellow;
lookAt();
}
if (Distance > ShootRange)
{
lookAt();
}
if (Distance < attackRange)
{
GetComponent.<Renderer>().material.color = Color.red;
attack ();
}
if (Distance > attackRange && Time.time > nextFire )
{
nextFire = Time.time + fireRate;
Instantiate(projectile, transform.position, transform.rotation);
}
}
function lookAt ()
{
var rotation = Quaternion.LookRotation(Target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * Damping);
}
function attack ()
{
transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
}
Destroy(gameObject)
or
Destroy(info.gameObject)
?
The former destroys the object the script is attached to.
Answer by Kali2048 · Oct 12, 2015 at 12:59 AM
have you checked that the bullets are not colliding with something when you shoot them ?
may be the gun or the character itself ?
if you spawn the bullet and it detect a collider then it'll be destroyed.
Your answer
Follow this Question
Related Questions
Idle , Move and Attack animations 0 Answers
BCE0020 error with animation 1 Answer
BCE0043 and BCE0044 errors, expecting ), found '.' and unexpected token ) 0 Answers
Rootmotion fall 0 Answers
Need help with automatic weapon firing! 2 Answers