Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

Damaging Enemy strangely not working.

$
0
0
I am trying to set up collision detection with the bullet prefab and the enemy. oddly when I shoot the enemy "Sometimes" the bullet will be deleted, other times it just goes right through (This is while firing consecutive shots). Regardless of what i tell it to do after detection a collision nothing happens really. I have a bullet prefab, a projectile script, and enemy script. the bullet has a sphere collider, and the enemy has a capsule collider. Is something wrong with the script? Or do you have tips on settings i may have forgotten to apply on the gameobject's components? using UnityEngine; using System.Collections; public class EnemyScript : MonoBehaviour { public float currentHealth; public int life = 0; void OnTriggerEnter(Collider other) { if (other.tag == "Bullet") { currentHealth--; Destroy(other.gameObject); } } } using UnityEngine; using System.Collections; public class projectileScript : MonoBehaviour { public Vector3 muzzleVelocity; public GameObject weapon; public GameObject muzFlash; public float TTL; public bool isBallistic; public float Drag; // in metres/s lost per second. // Use this for initialization void Start () { if (TTL == 0) TTL = 5; print(TTL); Invoke("projectileTimeout", TTL); weapon = GameObject.Find("BulletSlot"); var w = weapon.GetComponent(); w.clip--; Instantiate (muzFlash, transform.position, transform.rotation); } // Update is called once per frame void Update () { if (Drag != 0) muzzleVelocity += muzzleVelocity * (-Drag * Time.deltaTime); if (isBallistic) muzzleVelocity += Physics.gravity * Time.deltaTime; if (muzzleVelocity == Vector3.zero) return; else transform.position += muzzleVelocity * Time.deltaTime; transform.LookAt(transform.position + muzzleVelocity.normalized); Debug.DrawLine(transform.position, transform.position + muzzleVelocity.normalized, Color.red); } void projectileTimeout() { DestroyObject(gameObject); } }

Viewing all articles
Browse latest Browse all 1488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>