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 Uriel_96 · Dec 08, 2010 at 11:43 PM · collisioncolliderenemyshootsendmessage

How to make enemy damage in diferent parts of the object?

Hi, I have another question for this day. I am trying to do many ways to get damage the enemy by shooting diferent parts of the body and I'm not sure if it really works but that why I am asking a better way or the correct form to do it, but OK this is the script that in every part of the body in the enemy:

var damage = 5.0;
function CanDie(moredamage) {
var enemy = GameObject.FindWithTag("enemy").transform;
damage = damage + moredamage;
enemy.SendMessage("can_die",damage,SendMessageOptions.DontRequireReceiver);
}

for the bullet script is:

var damage = 2;
var damagereciver = true;
function OnCollisionEnter(collisionInfo) {
collisionInfo.other.SendMessage("canDie", damage, 
SendMessageOptions.DontRequireReceiver);
}

What I do its that before this the bullet has a script that detects if the object it touches is has a tag named "part" and all the parts of the enemy have that tag and have a Collider to. Ok, the really problem are 3 things.

  1. The script dosent work to well(It dosent work when you are far and you shoot, only when its closer)
  2. Cause of the collider on every part of the enemy the enemy controls to bad
  3. Sometimes I dont know why it dosent get on collision(I dont know if is because my bullet goes really fast or something like that)

But, Please answer I will really appreciate the answers.

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

2 Replies

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

Answer by Loius · Dec 09, 2010 at 03:39 AM

This line is wrong:

var enemy = GameObject.FindWithTag("enemy").transform;

That will only find one object tagged enemy.

Here's how I do it -

Enemy.js -

var health : int; var parts : Array();

function Start() { parts = GetComponentsInChildren( EnemyPart ); for ( var p : EnemyPart in parts ) { p.enemy = this; } } function ApplyDamage( amount : int ) { health -= amount; if ( health <= 0 ) Die(); }

EnemyPart.js -

var enemy : Enemy;

function ApplyDamage( amount : int ) { enemy.ApplyDamage( amount ); }

Then you just apply Enemy to the enemy's root object, and EnemyPart to each damagable part. Call a part's ApplyDamage function and it'll send the message to the Enemy itself.

Remember that objects should only handle the information they need to know. Your foot (EnemyPart) doesn't tell your mind (Enemy) how much damage your body has taken; it only tells you when it is hurt. It's up to your mind to handle that information.

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 Uriel_96 · Dec 10, 2010 at 02:13 AM 0
Share

but I dont know, I try it and it works but I need to try this one that you put to know if it works better. But this is not finished, I almost have problems with the enemy that its moving to wired.

avatar image Uriel_96 · Dec 10, 2010 at 02:19 AM 0
Share

Oh know, thanks, yeah I was rong, I check the game and I see that when I kill the enemy it dosent kills that enemy, kills another one, again thanks.

avatar image
0

Answer by Statement · Dec 09, 2010 at 12:44 AM

1: The script dosent work to well(It dosent work when you are far and you shoot, only when its closer)

Well, I don't see any script that is doing any shooting so I can't help you here, but perhaps it's linked with issue #3. Read on.

2: Cause of the collider on every part of the enemy the enemy controls to bad.

Sorry, this doesn't make any sense to me. Is this an animation issue?

3: Sometimes I dont know why it dosent get on collision(I dont know if is because my bullet goes really fast or something like that)

Yes, it is likely you're experiencing tunneling. Tunneling happens when the update intervals are too coarse and the object is moving too fast. I think you can try switching to continous physics, or change your bullet detection method to ray cast or sphere cast instead of moving entities around - which I presume you're doing now.

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 Uriel_96 · Dec 09, 2010 at 02:50 AM 0
Share

for the second one is that I have every part of the enemy(leg,head,foot, etc..) with a collider, but because of that the enemy starts moving to wired, but this dosent have to be with nothing of animation. And for the first one I already modify the question so please look it and please answer if you know.

avatar image Uriel_96 · Dec 09, 2010 at 03:01 AM 0
Share

dont worry I already find the answer of my question I only need to change collision to trigger but thanks anyway for your answer.

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

No one has followed this question yet.

Related Questions

How can i make a projectile attack travel through multiple enemies dealing damage to all of them? 1 Answer

Best way to handle melle attacks in a fast paced 2D game 0 Answers

Object moving too fast, so that the collider does not work (C#) 2 Answers

Problem with melee collision 3 Answers

Attack Player if Enemy is hit 0 Answers


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