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 Deatructo · Jan 02, 2014 at 04:26 PM · collisioncharactercontrollerenemyhit detection

Enemy character controller

happy new years unity community quick question i looked around first and did not find any info on this so i thought to ask here im trying to put a creature in my game with six legs and a spider like body its the free cave worm on the asset store i have it going and set up with AI but i ran into an issue the character controller collision capsule doesn't fit I changed the radius and heights to fit good but its either too big so if i shoot the air next to it it will hit the enemy or too small and i cant hit most of the body parts so has anyone come across a better way to do a better character controller if i could add more then one capsule i would be able to do it but i cant or don't know how anyone have any ideas I would be very appreciative.

UPDATE :

I have been playing around with it and i put colliders in the bones of the model so i can shoot each spot but i cant seem to figure out how to send the damage to my main body so i can kill it ive tried this

 using UnityEngine;
 using System.Collections;
 
 public class BodyPartdamage : MonoBehaviour {
 
     
     void Start () {
         
             if(other.GetComponent<CharacterDamage>() != null){
  
           
              other.GetComponent<CharacterDamage>().hitPoints -= damage;
         }                    
     
     }
     
     
     void Update () {
     
     }
 }

something i tested out but doesn't work im trying to get it to just send the damage to my main body when i shoot

Update : ive tried and failed again there has to be a simple way to do this this is what i tried this time but i cant figure out how to send the send the float damage with the message

 using UnityEngine;
 using System.Collections;
 
 public class BodyPartdamage : MonoBehaviour {
     public GameObject parent;
 
     // Use this for initialization
     void Start () {
     }
         public void ApplyDamage ( float damage, Vector3 attackDir, Vector3 attackerPos ){
                         if (parent != null)
                             {
                          parent.SendMessage("ApplyDamage");
             
         
         }
     }
 }





Update :

I tried this too .... i think i got closer but its giving me this error error CS1501: No overload for method ApplyDamage' takes 1' arguments.... i feel a little stupid at this point all i want is when my bullet hits the collider that is part of the bones to send rerout the message to my NPC's Damage handler

 using UnityEngine;
 using System.Collections;
 
 public class BodyPartdamage : MonoBehaviour {
     public GameObject parent;
 
     // Use this for initialization
     void Start () {
     }
         public void ApplyDamage ( float damage, Vector3 attackDir, Vector3 attackerPos ){
                 if (parent != null)
                             {
                  
                     
                          parent.GetComponent<CharacterDamage>().ApplyDamage(damage);
             
         
         }
     }
 }

this is what the weapon does when it hits an NPC layer

if(hit.collider.gameObject.GetComponent()){ hit.collider.gameObject.GetComponent().ApplyDamage(damage, direction, mainCamTransform.position);

but the collider im hitting doesent have the characterdamage script so i need it to reroute it to the game object that does using

public GameObject anyname;

to specified game object with the characterdamage script because it is the parent game object sorry for so much but im lost im not a good programmer (learning) so i realy cant see what im doing wrong

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Kyieon · Jan 02, 2014 at 11:39 PM

Try something like this. Its just pseudocode so you might need to adjust it.

 public void ApplyDamage(float bulletDmg, string bodyPartName){
     if(parent != null){
         if(bodyPartName == "leg"){
             float bodyPartMultiplyer = 0.25f;
             parent.GetComponent<CharacterDamage>().hitPoints -= (bulletDamage * bodyPartMultiplyer);
         }
     }else if...
 }
Comment
Add comment · Show 4 · 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 Deatructo · Jan 03, 2014 at 01:17 AM 0
Share

ok thank you so much trying it right now had to take a break lol

avatar image Deatructo · Jan 03, 2014 at 02:43 AM 0
Share

no dice messed with it for about an hour i put it in and made it work with the scripts and it partially worked the enemy was hurting its self... and my bullet did nothing i changed the name of the public void to something else so the enemy wouldn't hit itself but it still hit itself and i added its own little function in my weapon script and it still doesn't work im so stumped..

this is what i ended up with from that i removed some stuff

 using UnityEngine;
 using System.Collections;
 
 public class BodyPartdamage : $$anonymous$$onoBehaviour {
     public GameObject parent;
     
     public float DamageAmplifier = 0.25f;
 
     // Use this for initialization
     void Start () {
     }
         public void HitBodyPart(float damage){
            
             if(parent != null){
                 
                     float bodyPart$$anonymous$$ultiplyer = DamageAmplifier;
                     parent.GetComponent<CharacterDamage>().hitPoints -= (damage * bodyPart$$anonymous$$ultiplyer);
             }
             
         }
     
 }



AND

this is the change i made to rthe weapon script

 if(hit.collider.gameObject.GetComponent<BodyPartdamage>()){
                     hit.collider.gameObject.GetComponent<BodyPartdamage>().HitBodyPart(damage);
             }



had to do that because the enemy can also attack other npc and it was attacking itself but even with the change it still damages itself im sure i have to look into if there are tags set but i should be hitting it too if you would like to see the full script i cant post it here but i will be happy to share privately if you cant see the issue in these codes thank you again

avatar image Kyieon · Jan 06, 2014 at 09:51 PM 0
Share

Take the "HitBodyPart" function out of the start function :)

avatar image Deatructo · Jan 09, 2014 at 11:47 PM 0
Share

just tried it dident work either but the multiplier works now :)

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

Character Controller not ground object 1 Answer

Colliders doesn t collide with CharacterController 1 Answer

CharacterController collision disabled when modifying center 0 Answers

Rigidbody: how to get collisions for the current frame ? 0 Answers

How do I go about adding basic pathfinding to my enemy? 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