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 /
This question was closed Nov 05, 2016 at 09:05 PM by Zitoox for the following reason:

The question is answered, right answer was accepted

avatar image
-1
Question by Zitoox · Nov 04, 2016 at 06:06 PM · scripting problemcollisionnot workingignore

Collision being ignored

I am having trouble in making a cillinder show a message when it hits an Enemy. I was seeing a video about Counter-Strike when i thought "Oh, it would be a nice idea to use that same system!" Most FPS games use an invisible line that when find an enemy, activate a trigger that will make the enemy be hit instantly.

This makes impossible for the enemy to dodge hits, but it is very easy to make and pretty nice by the way. It would reduce my things to do list for now (i am developing the enemy) in my FPS.

The problem is that something is wrong here... I don't know if it is bcs i have been studying literally 3 different programming languages and i am kinda forgotting the basic things sometimes, but something is wrong with my script.

I made a simple script for now that WAS SUPPOSED to detect any gameobject that collide with my cillinder. When it collides, the script will detect if it is an enemy by searching if it is tagged as "Enemy". (Javascript)

 function OnCollisionEnter (Aim : Collision)
     {
         if(Aim.gameObject.tag == "Enemy")
         {
             Debug.Log ("TARGET HIT!");
         }
     }

The problem is that basically... It doesn't show the log! Why? I also changed it to just (Collision: Collision) and nothing changes, the log isn't shown. My cillinder does have a collider, the enemy does have a collider, i don't understand! Is it because i have two cameras or something? Also my cillinder is passing through objects. =(

Edit: Here are two screen shots. One is of my current test cillinder, and the other is from the Enemy. Hope it helps! alt text

alt text

enemy-min.png (253.2 kB)
cillinder-min.png (231.2 kB)
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

3 Replies

  • Sort: 
avatar image
0
Best Answer

Answer by tanoshimi · Nov 04, 2016 at 08:59 PM

You need a rigidbody component attached to your enemy.

"With normal, non-trigger collisions, there is an additional detail that at least one of the objects involved must have a non-kinematic Rigidbody" https://docs.unity3d.com/Manual/CollidersOverview.html

Comment
Add comment · Show 5 · 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 Zitoox · Nov 04, 2016 at 09:15 PM -1
Share

Okay, i didn't considered it. It works =)

But now when it hits my enemy he is knocked away...

avatar image tanoshimi Zitoox · Nov 04, 2016 at 09:35 PM 0
Share

Yes, because that's what happens when two objects collide. $$anonymous$$ake the mass of your projectile smaller if you want it to apply less force.

avatar image Zitoox tanoshimi · Nov 04, 2016 at 11:57 PM -1
Share

By the way, do you know how to ignore a tag when using OnCollision? Something like:

 function OnCollisionEnter (Collision : Collision)
      {
          if (Collision.gameObject.tag == "Aim")
          {
              Ignore.Object
          }
      }

Something lik ethis.

Show more comments
avatar image
-1

Answer by ToasterKyle · Nov 04, 2016 at 08:17 PM

I don't see my original answer so I'm posting a new one as a sort of edit to my original(if you can even see it) but also try using Aim.collider.tag instead of Aim.gameObject.tag. Not sure what the difference is but once I had a problem similar to yours and I believe it was fixed by changing that. It was a while ago though

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 ToasterKyle · Nov 04, 2016 at 08:17 PM

Is the Cylinder a trigger? Also, try just Debug.Log outside of the if statement so that when the enemy hits anything it will log it just for a test, if or when that works you can delete it and do further testing

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 Zitoox · Nov 04, 2016 at 08:27 PM 0
Share

I already tried with trigger options and it doesn't change anything. Also, as far as i know you don't need to use triggers when you are using OnCollision. (I use it in other projects without triggers and it works fine) And even with the Debug.Log outside the if statement, it still doesn't work. The command Debug.Log works normally, which prove that it is NOT a bug/glitch. The problem here is that the function isn't being called or something like this, but i don't know why. $$anonymous$$y cillinder clearly is IGNORING the other colliders, and this is making the script bug, but i don't know why and how to solve it =\

Follow this Question

Answers Answers and Comments

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

Reference to another script not working, not throwing any errors 0 Answers

SetActive messes up everything? 1 Answer

Collision with a coin 0 Answers

If two PlayerPrefs are on? 2 Answers

Character Controller NOT COLLIDING. 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