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 /
  • Help Room /
avatar image
0
Question by The Hero · Sep 19, 2015 at 08:51 PM · 2dtrigger2d-physicsdamage

OnTriggerEnter2D Not Working

Rigidbody2D is not set to kinematic, OnTriggerEnter2D is spelled correctly and my box collider 2D is a trigger, and its not working...

 using UnityEngine;
 using System.Collections;
 
 public class Damage : MonoBehaviour {
     
     public float Damage2 = 50;
 
     public AudioSource SoundEffect;
 
     void OnTriggerEnter2D(Collider2D other)
     {
         if (other.tag == "Player")
         {
             other.GetComponent<HealthSystem>().Damage = Damage2;
             SoundEffect.Play ();
         }
     }
 }
 
Comment
Add comment · Show 6
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 hexagonius · Sep 19, 2015 at 09:25 PM 0
Share

what's with the collider? How does that move?

avatar image The Hero hexagonius · Sep 19, 2015 at 09:41 PM 0
Share

Using unitys standard "2D" asset.

avatar image hexagonius · Sep 19, 2015 at 09:54 PM 0
Share

I meant the collision partner. you described only one member, right? if not, the other object might not have a collider.

avatar image The Hero hexagonius · Sep 19, 2015 at 09:59 PM 0
Share

I have a character with an axe as a weapon, the axe itself has the script attached to it, and activates it when needed. It also has a 2d box collider trigger.

avatar image hexagonius · Sep 19, 2015 at 10:22 PM 0
Share

and you're trying to hit enemies which have colliders? How is everyone moving? translating? If so switch to addforce or velocity. animation should run in physics update mode... your info is just not enough to guess more.

avatar image The Hero hexagonius · Sep 19, 2015 at 10:29 PM 0
Share

Every character in my scene is using a 2D box collider, they move by adding velocity to their rigidbodies. Im using $$anonymous$$ecanim to animate each character. $$anonymous$$y melee weapon system works by enabling a gameobject with a collider on it with the Damage script. When you press the spacebar, the character will do an animation where he swings his axe. The collider is enabled during this animation. However, if you try to use your axe on an NPC, nothing happens. No errors, nothing.

http://oi61.tinypic.com/2wrnqso.jpg

In the image above, you can see that the axes damage trigger is clearly co$$anonymous$$g in contact with the character, yet nothing happens.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by hexagonius · Sep 19, 2015 at 11:13 PM

the animation looks quite fast. Is the position fix relative to the player? because then an overlapcircle might do.

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 The Hero · Sep 19, 2015 at 11:25 PM 0
Share

Oh, ok. I slowed the animation and its working now. Thanks for your help.

Edit: Never$$anonymous$$d, its still not triggering. But the wierd thing is that if I add the damage script to a gameobject with nothing other then a box collider trigger, then it works.

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

33 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 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

Need help with OnTriggerExit2D 0 Answers

Why do I keep getting a null reference? Its not null! 0 Answers

Having my GameObject passing trough floor during one frame ( 2D Platformer ) 1 Answer

Arkanoid-like bounce troubles 1 Answer

Box Collider 2D not functioning - Object bound to mouse,Box Collider 2D not functioning - object bound to mouse 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