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 jiroldan · Mar 30, 2017 at 11:23 AM · collisiononcollisionenter

OnCollisionEnter called while box colliders not touching

Hello,

I've got a problem with Unity3d 5.5 and OnCollisionEnter that is called when objects are near but not touching themselves.

I create a simple scene with 2 Cubes (3d) Scale=1x1x1, Box Collider Size=1x1x1, and RigidBody (not using gravity)

I position "Cube1" at 0x0x0 (left cube) and "Cube2" at 4x0x0 (right cube) (Cube2 should touch Cube1 when Cube2.transform.position.x = 1)

I assign the following Script to Cube2:

     using System.Collections;
     using System.Collections.Generic;
     using UnityEngine;
     public class CollisionDetector : MonoBehaviour {
         private void OnCollisionEnter(Collision collision)
         {
             GameObject other = collision.gameObject;
             Debug.Log(string.Format("ENTER: {0} (Pos={1},{2},{3})", other.name, transform.position.x, transform.position.y, transform.position.z));
         }
         public void OnCollisionExit(Collision collision)
         {
             GameObject other = collision.gameObject;
             Debug.Log(string.Format("EXIT: {0} (Pos={1},{2},{3})", other.name, transform.position.x, transform.position.y, transform.position.z));
         }
         public void OnTriggerEnter(Collider other)
         {
             Debug.Log(string.Format("TRIGGER ENTER: {0} (Pos={1},{2},{3})", other.name, transform.position.x, transform.position.y, transform.position.z));
         }
         private void OnTriggerExit(Collider other)
         {
             Debug.Log(string.Format("TRIGGER EXIT: {0} (Pos={1},{2},{3})", other.name, transform.position.x, transform.position.y, transform.position.z));
         }
     }


I press Play

If I change in editor the X of Cube2 Transform Position and make it smaller in order to get closer to Cube1, the event OnCollisionEnter is called when the X = 2.8 (Cubes are not touching themselves!!!) Console Log: ENTER: Cube 1 (Pos=2.8,0,0)

Also when I separate the cubes changing the position X of Cube 2, OnCollisionExit is called when Cube2 X = 2.8 Console Log: EXIT: Cube 1 (Pos=2.81,0,0)

If I set the Box Collider of Cube 2 as "Is Trigger", then the functions OnTriggerEnter and OnTriggerExit are called ok when Cube2 X position = 1 Console Log: TRIGGER ENTER: Cube 1 (Pos=0.94,0,0) Console Log: TRIGGER EXIT: Cube 1 (Pos=1.04,0,0)

do you know why is failing OnCollisionEnter and OnCollisionExit?

Thanks for your help!!!

NEW INFO:

In the next url, you can download the zip with the project folder: https://www.dropbox.com/... (removed)

If I export it as a package and import that package in a new project... it works fine ?????

Any explanation? Help please!!!

Thank you very much for your help

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

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by jiroldan · Mar 31, 2017 at 11:38 AM

Solved.

I comment, in case someone has the same problem:

I had been testing the PhysicsManager properties (Edit/Project Settings/Physics) and I had the "Default contact offset" set to 0.9 instead of the default value 0.001, so collisions ocurred 1.8 units further than they should.

Greetings, jiroldan.

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

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

CS1525 Unexpected symbol '=', HELP!!! 2 Answers

OnCollision Enter function is not being read 1 Answer

How can i store all colliders of colliders which collide with a prefab? 1 Answer

Collisions in Editor Test Runner 0 Answers

Player/platform collision not detected 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