Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Inan-Evin · May 22, 2011 at 12:07 AM · collisionmelee

Very Simple Melee Attack Collision Question

Hello everyone, i have 1 Team A guy,1 Team B guy,they are enemies to each other and they all have AI scripts, but i have problem about the collision of the swords. Team A guy have 300 health,which means he will be dead in 6 hits,but he's dying too quickly,because the function always happens when sword it's colliding,i want to make it to happen one per colliding,here is my code:

 function OnCollisionEnter(collision : Collision) 
 {
  
    if (collision.gameObject.tag=="ZulDurak") {
   
 
    ZulDurakAI1.healthzul -= 50;
 
  
    }
     }

i tried OnTrigger but didn't work,any ideas ?

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
0
Best Answer

Answer by Owen-Reynolds · May 22, 2011 at 02:38 AM

The sword is either a Collider or a TriggerBox (a Collider with isTrigger checked.) You can only use the Trigger functions for trigger boxes, and vice-versa. I'd guess you want the sword to be a triggerBox, so it can swing through without doing some wierd pushing stuff.

Your code should work. My guess is that it hits an arm, then the body, maybe bounces off and hits again, then clips the same arm, then the other arm... . If health always drops to 0 immediately, my guess is wrong.

One fix is to add a bool so it can only do damage once/swing:

 // I'm used to C#, so guessing javascript:
 var swordReady : bool = false;

 // have to "look up" swordReady if different scripts
 if( [starting swing] ) swordReady=true;

 // in OnTriggerEnter:
 if (swordReady && collision.gameObject.tag=="ZulDurak") {
     swordReady=false;
     ...
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 Inan-Evin · May 22, 2011 at 11:22 AM 0
Share

didn't work, i tried using it but AI code just gone, in the panel it said look view is 0 or sumthing like that,simply when i tried doing such thing, none of them died.

avatar image Owen-Reynolds · May 22, 2011 at 10:28 PM 0
Share

But do you understand the idea of testing a lot to see exactly what is wrong? Did you check to see if your code snaps to -600 health right away, or stutters down? Do you get the idea of using a True/False to make sure something can only happen once? Those things will solve lots of problems.

avatar image
1

Answer by Eli-Davis · May 22, 2011 at 12:33 AM

instead of onCollisionEnter, try OnCollisionExit, so the script is only called once the collider comes off the player, or atleast I think That will work.

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 Owen-Reynolds · May 22, 2011 at 02:25 AM 0
Share

There are the same number of Enters as Exits. You're probably thinking of OnCollisionsStay, which can run every frame.

avatar image Inan-Evin · May 22, 2011 at 11:21 AM 0
Share

thank you but didn't work :/

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

OnTriggerStay2D only detecting trigger collisions while moving 3 Answers

Full Performance On Melee Combat 0 Answers

Recommended approach for melee combat system 2 Answers

melee combat 0 Answers

how should i go along making a melee system 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