Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by JoshMBeyer · Mar 19, 2014 at 09:33 AM · collisionenemyprojectiledamageapply

Damaging Enemy strangely not working.

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<weaponScript>();
         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);
     }
 }
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image robcbryant · Mar 19, 2014 at 10:10 AM 1
Share

How fast is your bullet moving? Colliders don't work very well at high speed collisions.

Edit: Test this out--try setting the bullet speed to something much slower -- like 1/4 of the current speed and see if they stop passing through the enemy.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Player's projectile communicating with Enemy 3 Answers

Can I make an Enemy Insatiate a projectile object? 1 Answer

Damage on prefab collision? 0 Answers

Damage on collision with player.. 1 Answer

Collision Damage 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges