Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  4. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

BoxCollider not working properly since updating to new version

Discussion in 'Physics' started by JeffreyA, Jul 11, 2018.

  1. JeffreyA

    JeffreyA

    Joined:
    Jun 6, 2017
    Posts:
    13
    Hey,

    Long post below but i tried to explain everything in detail.

    As the title says, my box collider isnt working properly since i updated to unity 2018 20f2.
    It was working fine in version 2018 11f1. And i dont know if the issue is a result of the update. The same problem occurs when i run the scene on another computer (same version).

    The scene setup:
    I started a new project and made the exact same setup for experimenting and debugging as in my original project, with the same result. So the mistake is reproduced.

    ObjectA --> boxcollider, istrigger, rigidbody, boxcollider is around the object and position of ObjectA = 0,0,0.
    Line --> boxcollider, arround the object and position of the line is -1003, 0, 0.
    See screenshot below for a clearer view.

    Script attached to Line object:

    Code (CSharp):
    1.  private void OnTriggerEnter(Collider coll)
    2.     {
    3.         Debug.Log("OnTriggerEnter: " + coll.name);
    4.        
    5.     }
    When i play the scene and i drag the Line object manually into ObjectA i get the Debug.Log message, so the OnTriggerEnter is recognized and it works.

    So far, so good:)

    The problem:
    In both my original project and the new project i use for debugging, i use a scale resize script on the line object to let it draw (scale) a line to ObjectA, the idea is that when the Line reaches ObjectA the OnTriggerEnter activates.
    In Unity 2018 11f1 that worked great (no idea if it was luck that it worked in that particular version).

    The problem in Unity 2018 20f2 (and other version > 2018 11f1) the OnTriggerEnter is only recognized when the line is so large that it has passed ObjectA. In other words, the OnTriggerEnter has a delay, but only when i use the scaling script, when i drag the line (without scaling) manually in ObjectA it works within a second and also when i scale the line manually in the inspector, it works as well.
    One last thing i noticed is when i increase the distance between line and ObjectA, the point where the OnTriggerEnter activates is further away.

    Image of my scene and the problem explained in the screenshot:


    Can someone explain this to me? I tried so much, changing rigidbody to other object, used 2d box-colliders, 3d box-colliders etc, OnCollision instead of OnTrigger.

    My scaling script looks as follows and i know that the coroutine never stops, but for now i only need the the debug.Log from the OnTriggerEnter (code above).

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class ScaleScript: MonoBehaviour {
    6.     private Vector3 temp;
    7.     private float speed = 3f;
    8.     private bool touched = false;
    9.     public GameObject line;
    10.  
    11.     void Start () {
    12.        StartCoroutine(ScaleLine(line));
    13.     }
    14.  
    15.     IEnumerator ScaleLine(GameObject line)
    16.     {
    17.         Debug.Log("Coroutine Start");
    18.         while (touched == false)
    19.         {
    20.             temp = line.transform.localScale;
    21.             temp.x += Time.deltaTime * speed;
    22.             line.transform.localScale = temp;
    23.             yield return null;
    24.         }
    25.     }
    26. }

    If someone knows why this happens and why the OnTriggerEnter doesnt work immediately i would like to hear it and thanks in advance.

    Jeffrey