0
\$\begingroup\$

Scene setting:

Object A: Rigidbody, kinmeatic Box collider, is trigger true.

Object B: Box collider, is trigger true.

Script is on Object A:

void FixedUpdate()
{
    if(increaseScale)
    {
        transform.localScale += transform.forward* speed;

        // when to stop 
        if ((AEForward * transform.localScale.z).sqrMagnitude >= range * range)
            increaseScale = false;
    }
}

void OnTriggerEnter(Collider other)
{
    Debug.Log(other.transform);
}

No log message when part of object A is inside B.

And the funny part is if I use it on a sphere collider, it works. (use transform.localScale += new vector3(1,1,1)* speed; instead )

\$\endgroup\$
4
  • \$\begingroup\$ Have a look at the collision matrix at the bottom. Double check that your setup will actually work. \$\endgroup\$
    – mr-matt
    Nov 19, 2018 at 3:38
  • \$\begingroup\$ Not physical layer setting problem, because they all in default layer, and the sphere object have no problem. \$\endgroup\$
    – Shitman
    Nov 21, 2018 at 0:49
  • \$\begingroup\$ The collision matrix isn't related to layers. It's about the colliders and rigidbodies used. \$\endgroup\$
    – mr-matt
    Nov 21, 2018 at 1:14
  • \$\begingroup\$ I'd use an OverlapBox query for this, rather than dynamically scaling a collider. \$\endgroup\$
    – DMGregory
    Apr 18, 2020 at 11:54

1 Answer 1

0
\$\begingroup\$

I believe that you need to have a Rigidbody attached to both object A and object B to register a trigger collision. It looks like you only have one attached to object A.

\$\endgroup\$
3
  • \$\begingroup\$ Your case is OnCollisionEnter(). \$\endgroup\$
    – Shitman
    Nov 16, 2018 at 22:36
  • \$\begingroup\$ @Shitman It's actually not. You must have both a collider and a rigidbody attached to both objects in order to detect collisions. \$\endgroup\$
    – user115399
    Dec 22, 2018 at 10:31
  • \$\begingroup\$ Are you sure? My scene work on sphere collider. \$\endgroup\$
    – Shitman
    Dec 27, 2018 at 4:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .