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 Tavis · Sep 26, 2012 at 11:45 AM · c#collisiononcollisionenter

Simple Collision Detection not working. [Solved]

Pretty much it comes down to collision in my game doesnt seem to be working. In my game I have the character moving constantly to the right, as he passes through a cube with its Mesh renderer off I just want it to print "hit" ( at the moment anyway, my plan was for somthing else but since collision wasnt working I just want the debug.log to work).

Both objects have colliders. (tried is trigger on/off on both or either)

Both objects have Rigidbodies (tried without rigidbodies on both or either one and tried is kinematic on both or either)

I have tried OnCollisionEnter and OnTriggerEnter using the exact C# scripts.

The guy I'm working with has this code that works for collision in his level.

 void  OnCollisionEnter ( Collision myCollision  ){
         rigidbody.AddForce(0,force,0);
     }


However when I copypaste it into the script tied with my objects, it doesnt work. I've made sure my objects are exactly like the ones he is using in his level.

I've read around 10 questions on this site about collision, tried their answers and still nothing. With the limited unity knowledge I have I would assume somehow ive changed some settings or somthing without knowing it. Since I can load up my friends level and the EXACT collision script works. Any help would be greatly appreciated.

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

· Add your reply
  • Sort: 
avatar image
0

Answer by Tavis · Sep 26, 2012 at 11:57 AM

After I posted this I read through some more previous questions and found one that linked this

http://docs.unity3d.com/Documentation/Components/class-MeshCollider.html

The table at the bottom is beyond helpful, I simply must have tried the wrong combination every time :(

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 _louisreed · Feb 24, 2015 at 02:16 PM 0
Share

Hi can you please provide the actual solution? I am having the same problem! I'm still learning how to use C#/Unity so the api still confuses me a little bit.

avatar image
0

Answer by Riazu · Jan 12, 2016 at 10:05 AM

Hi there, You need to check the object if your player is colliding with the specific object or not.

For that you need tags or names or something specific. For Example, I am making a shooting game and I want to check if my bullet has collided with the enemy's collider or not so I will do it this way,

void OnCollisionEnter(collision col) { if (col.game.tag == "Enemy") { //Kill the player or play its death animation or replace it with its ragdoll. } }

In short, you need to check whether the object is colliding with that specific object or not. If it is not clear, please leave a comment... I'll try my best to explain in more detail.

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 marcoleoni · Jun 15, 2016 at 07:45 AM 0
Share

Hi Riazu,

i'm a beginner Unity users and my "game" should be very simple. I would like to grab objects without collider with the shelfs, couch etc...so, how could i do? I'm using the same version of Unity.

Thanks

avatar image
0

Answer by unity_ngP8_Fl6_Peiuw · Nov 27, 2018 at 10:18 PM

Check the layer that the offending object is on. I had the same sort of 'it isn't colliding' problem and none of the discussion mentioned layers. The object I was having problems with was assigned to the 'default' layer and everything else was on 'environment' or 'terrain' or 'player' and it wasn't until I asked the question about what layers are used for that I found out that in the Edit->project->physics menu there is a table of layers and you can select those that do or do not collide with each other. See https://docs.unity3d.com/Manual/LayerBasedCollision.html

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

14 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

Related Questions

Collision issue with SetParent (C#) 1 Answer

Jump on the ground 2 Answers

On Trigger Enter, Collide with object, specific collision 1 Answer

Multiple Cars not working 1 Answer

how to stop my scene on collision.. 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