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 cheese_flavour · Mar 26, 2016 at 09:06 AM · 2dcollisiontrigger

How do I get collision and trigger to work?

I'm new to Unity and am trying to create a simple 2d game. However I cannot get collisions or triggers to work under any circumstances. I even created an entirely new 2d project in unity with only 2 objects colliding to remove any other factors but was unable to get it to work. Here is the C# script I've been using:

 using UnityEngine;
 using System.Collections;
 
 public class Test : MonoBehaviour {
     void Start()
     {
         print("Start: " + gameObject.name);
     }
 
     void OnTriggerEnter(Collider other)
     {
         print("OnTriggerEnter: " + gameObject.name);
     }
 
     void OnCollisionEnter(Collision col)
     {
         print("OnCollisionEnter: " + gameObject.name);
     }
 }

Because this is a completely fresh project the collision matrix (for both 3d and 2d) are set to interact with all layers, so that's not the issue. I also make sure to have colliders on objects and a rigidbody on one of them.

Based on search results for similar problems I've tried the following:

I just create 2 game objects, 1 circle to drop on a square. For the square I just add a default 2d box collider and the script. For the circle to be dropped I added a default 2d rigidbody and a default 2d box collider. Gravity will do the rest.

  1. When I start the game I only get the start message from the script. The circle drops and stops at the square, but no further messages are fired. I expected the OnCollisionEnter message to be fired.

  2. If I set isTrigger on the square, the circle drops through it as expected, but no message is triggered. Similar behaviour if i set isTrigger on the circle or both, however since the circle has no script I wouldn't expect that to work.

  3. I tried switching to continuous collision detection on the rigidbody, but this did not help.

  4. I tried increasing the mass on the rigidbody, using several different values up to 10000, however this had no effect (nor should it?).

  5. I tried moving the script to the circle, and also having the script on both. The only message which is ever fired is still the start message for each object.

  6. I tried using 2d circle colliders, edge colliders and polygon colliders.

In my actual project I've tried moving the objects with rigidbody.AddForce and rigidbody.velocity instead of just using gravity. However this worked no better.

What could be the problem?

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

Answer by LazyElephant · Mar 26, 2016 at 09:21 AM

You're using the 3d versions of OnCollisionEnter and OnTriggerEnter but using 2d rigidbodies and colliders. You need to use OnCollisionEnter2D and OnTriggerEnter2D.

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 Max_power1965 · May 24, 2020 at 03:49 PM

I also had really a lot of problems when configuring the collision between game objects. After years I wrote every tips in this article https://gamedevelopertips.com/unity-collision-detection-2d/, I'm sure it'll be helpful if you want to set up properly you collider/triggers properly.

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

Problems with using OnTriggerStay2d 0 Answers

Detect the objects staying on top of the Particles 0 Answers

2D: Destroy object with dynamic collider after exiting object with static collider 1 Answer

Get tile from trigger 0 Answers

OnTriggerEnter2D and OnCollisionEnter2D not working 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