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
1
Question by ObviouslyInsane · Aug 19, 2011 at 08:21 PM · collisioncolliderenemymelee

Problem with melee collision

Hi guys, I have a simple script here attached to a melee weapon. It isn't dealing any damage when I hit an enemy:

 var damage : float;
 var force : float;
 
 function OnTriggerEnter (col : Collider) {
     if(col.Tag == "Enemy")
         GetComponent("CharacterDamage").hitPoints -= damage;
     Debug.Log("Collided!!!!!");
         
         
     }

Can someone give me an idea what I'm doing wrong? I have a box collider attached to the melee weapon and a sphere collider on the enemy that is set to trigger.

Comment
Add comment · Show 2
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 stopsecret · Aug 19, 2011 at 08:40 PM 0
Share

This is just a shot in the dark, but ins$$anonymous$$d of calling col's tag, have you tried col.transform.tag? Also, are there any javascript errors that show up? Also, If I remember correctly, calling OnTriggerEnter call's the melee weapon's trigger, not the trigger it hits. Hope this helps!

avatar image ObviouslyInsane · Aug 19, 2011 at 08:57 PM 0
Share

No I haven't tried that yet but I will now. I'm also not getting any errors at all. And thanks for the tip about OnTriggerEnter, I'll keep trying.

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by DaveA · Aug 19, 2011 at 10:21 PM

tag is lower case 't'

HEY GUYS! members and variables tend to start with lower case. Functions and Classes start with Upper Case. Second question this minute with this same type of problem

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

Answer by ObviouslyInsane · Aug 20, 2011 at 03:46 AM

Ok I have revised the script but it still isn't working. The debug.log statement isn't even being called. Here's the script now:

 var damage : float;
 var force : float;
 
 function OnControllerColliderHit(hit : ControllerColliderHit){
 
 if(hit.gameObject.CompareTag == "Enemy")
         GetComponent("CharacterDamage").hitPoints -= damage;
         Debug.Log("Collided!!!!!");
         
         
     }

Anyone else have an idea what's wrong?

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

Answer by sharp7j · Feb 02, 2016 at 05:29 PM

If its a 2D game you have to use OnTriggerEnter2D(Collider2D other)

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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Decreasing Player Health On Collision with Enemy 2 Answers

Fist Punch Collision 0 Answers

Enemy Collision Wont Work! PLEASE HELP 0 Answers

Damage on collision with player.. 1 Answer

Enemy Cube going through walls. 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