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 thenachotech1113 · Jun 05, 2012 at 12:19 AM · enemycollidersbulletdamageheadless

coliders are not working

hey, so i`m making a game and the bullets that hit the player are damadging him but the ones that hit the ennemy are not, the player is a capsule all made in Unity but the gun, the turret was fully made in cheeta 3D so I added a box colider to it and tried just adding coliders in the prefab options annyway I cant find a reason for this to hapen other than a bug. so here are the codes I used.

 // under update in the shooting code
 if(Input.GetButtonDown("Fire1")&& fire)
     {
         if (auto){}
         
         else
         {
         clone = Instantiate(projectile, transform.position, transform.rotation);
         clone.velocity = transform.TransformDirection( Vector3 (0, 0, speed));
         AudioSource.PlayClipAtPoint(sound, transform.position, 1);
         bulletAmount -= 1;
         }
     }    


 // under the health script and update
 var dead = false;
 var health = 100;
 var damage = 10;
 var player = true;
 var ennemy = false;
 var PlayerHealthDisplay: GUIText;
 
 function DisplayAmount () {
     PlayerHealthDisplay.text = "" + health;
 }
 
 function Start () {
 
 }
 
 
 
 function OnControllerColliderHit(hit : ControllerColliderHit) 
 {    
     
     if (hit.gameObject.tag == "fallout")
     {
         dead = true;
     }
     
     if (hit.gameObject.tag == "bullet")
     {
      if (player)
      {
      health -= damage;
      }
      if (ennemy)
      {
      health  -= damage;
      }
     }
     
     if (health < 1)
     {
     dead = true;
     }
     
 }
 
 function Update()
 {
         if (dead && player)
        {
            Debug.Log("Died, Respawning!");
            health = 100;
            transform.position = Vector3(-9,2,-48);
            dead = false;
        }
        if (dead && ennemy)
        {
                Destroy(gameObject);
        }
        
 }

 // and under the bullet code
 var lifeTime = 100;
 
 
 function Awake()
 {
     Destroy (gameObject, lifeTime*Time.deltaTime);
 }
 function OnCollisionEnter(collision : Collision)
 {
     Destroy (gameObject,0.1);
 }


sorry for the ton of code and thank you all

Comment
Add comment · Show 2
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 PforPepsi · Jun 05, 2012 at 01:32 AM 1
Share

http://unity3d.com/support/documentation/ScriptReference/Collider.OnCollisionEnter.html According to the document, one collider must have rigidbody attached to it. You should try attaching to bullet or something.. i guess..

avatar image PforPepsi · Jun 05, 2012 at 01:35 AM 1
Share

Also, CharacterControllerHit only activates when you use $$anonymous$$ove function attached. I'm not sure because when i tried, it didn't work at all.. Just in case, here is the reference http://unity3d.com/support/documentation/ScriptReference/CharacterController.OnControllerColliderHit.html

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Driseus · Jun 05, 2012 at 09:31 PM

Hey, try to add Rigidbodys with collisiondetection to your enemys this should work :).

Comment
Add comment · Show 1 · Share
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 thenachotech1113 · Jun 12, 2012 at 12:09 AM 0
Share

ok great thank you

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Staged bullet damage? 1 Answer

How to create an NPC enemy which can take damage and be killed when its energy or health reaches zero? 2 Answers

Only damage one object with "Enemy" tag 2 Answers

Player Damage to enemy damage melee system 0 Answers

Bullet Shoot At Enemy Position 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