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 Mystic 2628 · May 10, 2014 at 10:45 PM · collision

Dealing damage to specific body parts?

I've been trying to deal damage to the body parts of a ragdoll for the last couple of hours here and so far I have managed to create a basic damage system that does indeed deal damage to the ragdoll, just not specifically. For some unknown reason no matter where the bullet hits my ragdoll it always deals damage to every body part.

I have a debug set up to tell me which body parts have been hit and how much damage has been done to them, but even if I hit my ragdoll in his left arm, it will tell me that his right leg has been hit for example. I also told the editor to log every object the bullet hits, and despite being certain that it only hit Mesh 5, the upper arm/Shoulder, it continues to deal damage to all body parts. Incase it is relevant, I have the ragdoll grouped into all its different parts and each body part is a child of the group. For example, the group, Hips, Contains Mesh 4 as a child, which is what I've set the editor to collide with. I have the script here, written in JS:

 #pragma strict
 
 var bodyContact = ContactPoint; 
 var Col: Collision;
 var playerHealth = 100;
 var chestImpact : float = 30.0f;
 var headImpact : float = 60.0f;
 var hipImpact : float = 20.0f;
 var armLegImpact : float =    15.0f; 
 var footHandImpact : float = 7.0f;
 
 function Update ()
 {
     if(Input.GetKeyDown(KeyCode.H))
     Debug.Log (playerHealth);
 }
 
 function OnCollisionEnter (Col: Collision)
 {
     if(Col.gameObject.name == "Grouped player")
     {    
         Destroy(gameObject);
     }
     if(Col.gameObject.name == "Mesh9") //Chest
     {
         print ("Collided with Chest");
         playerHealth -= chestImpact;
         Debug.Log ("Did" + chestImpact);
     }
     if(Col.gameObject.name == "Mesh 6" || "Mesh 5" || "Mesh 3") //Left arm
     {
         print ("Hit left arm");
         playerHealth -= armLegImpact;
     
     }
     if(Col.gameObject.name == "Mesh 11" || "Mesh 12" || "Mesh 13") //Right leg
     {
         print ("Hit right leg");
         playerHealth -= armLegImpact;
     
     }
 }
 
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 Jeff-Kesselman · May 10, 2014 at 10:49 PM

Um your IF syntax is way off.... for instance....

  if(Col.gameObject.name == "Mesh 6" || "Mesh 5" || "Mesh 3") //Le

Is saying "If the name is "Mesh6" OR the string "Mesh 5" is true OR the string "Mesh 3" is true.

In Javascript, a string by itself is always true, unless it is null or undefined.

What you need to say is

 if( (Col.gameObject.name == "Mesh 6") || 
      (Col.gameObject.name == "Mesh 5") ||
      (Col.gameObject.name == "Mesh 3"))

This is a good example of somewhere where Unityscript's looseness screwed you up. In C# the compiler would have just objected to it all

In C# you could use a switch statement which would be a lot cleaner. Im not sure if UnityScript does switch on string values or not, but it might. Here are the docs for the switch statement.

In general, as your programs get more complex, you will find its significantly easier to shoot yourself in the foot with UnityScript then C#.

Comment
Add comment · Show 2 · 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 Mystic 2628 · May 16, 2014 at 09:34 PM 0
Share

I will probably end up using C# eventually, but for this project, it's staying as JS.

avatar image Mystic 2628 · May 16, 2014 at 10:03 PM 0
Share

Here's the updated code, which seems to still be broken. The debug messages aren't appearing at all now. if( (Col.gameObject.name == "$$anonymous$$esh 11") || //Right leg (Col.gameObject.name == "$$anonymous$$esh 12") || (Col.gameObject.name == "$$anonymous$$esh 13")) { print ("Hit right leg"); playerHealth -= armLegImpact; }

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

21 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 avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Collision I dont understand 1 Answer

How to load a scene on collision 2 Answers

Physics2D.OverlapAreaAll/NoAlloc fails detecting object in puzzling manner 1 Answer

Weird collision error when using waypoint script... 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