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 dabvid · Oct 28, 2014 at 06:14 PM · collisiontriggerevent

Collision not triggered by box collider

I'm starting out a 2D game. When the rocket collides with the floor nothing happens. Both sprites have box colliders. The rocket has "Is Trigger" checked.

OnTriggerEnter2D is never called in the rocketScript when it collides with the floor.

Please check the Gameobjects and rocketScript below.

alt text alt text

-----------------------------rocketScript.cs-----------------------------

 using UnityEngine;
 using System.Collections;
 
 public class rocketScript : MonoBehaviour {
 
     float camYSize;
 
     // Use this for initialization
     void Start () {
         camYSize = Camera.main.orthographicSize;
     }
     
     // Update is called once per frame
     void Update () {
         if (transform.position.y < -camYSize) {
             GameObject.Destroy(gameObject);
         }
     }
 
     void OnTriggerEnter2D( Collider2D other )
     {
         Debug.Log("Trigger");
     }
 }
screenshot 2014-10-28 15.53.00.png (58.7 kB)
screenshot 2014-10-28 15.53.24.png (27.3 kB)
Comment
Add comment · Show 1
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 Ali-hatem · Oct 29, 2014 at 08:38 PM 0
Share

ok guys i tested it and i was wrong about OnTriggerEnter2D() can't detect non trigger object . so i will delete the answer so it don't confuses the others.

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by tanoshimi · Oct 29, 2014 at 11:16 AM

I don't see anything wrong with the logic in your code and, sure enough, I can make your exact setup work just fine with a couple of simple sprites in a scene. My suggestions of where you might be going wrong are:

  • The box collider on your rocket is very small (0.0001 wide). If your rocket is moving fast, it is possible that a collision is not being detected as the collider passes through the floor and out the other side in a single frame. Try to change the scale of your objects to make the collider bigger (or slow the rocket down to see if that makes a difference).

  • Your Update() method is destroying the rocket if it falls below the bottom of the camera view, but I notice your floor object has a negative y value. Is there any chance your script is destroying the rocket before it's had chance to collide with the floor? (try commenting out line 16).

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 dabvid · Oct 29, 2014 at 04:56 PM 1
Share

Thank you a lot!! It was the width (0.0001) that caused the collision not to trigger. Would vote you up but my reputation is not enough (yet).

avatar image
1

Answer by Zavirjuha · Oct 29, 2014 at 10:06 AM

Both objects should have rigidbodies component to make OnTrigger works.

Comment
Add comment · Show 2 · 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 tanoshimi · Oct 29, 2014 at 11:11 AM 1
Share

This is just nonsense.

avatar image mrVentures tanoshimi · May 30, 2020 at 08:34 PM 0
Share

Haha I know, but it's true

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

Plane flyby triggering/help 1 Answer

How do I trigger an event (health loss) only once? 3 Answers

create event on collision 2 Answers

Activate trigger if items colected 1 Answer

If gameObject's center passes through a trigger? 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