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\$
  • \$\begingroup\$ Have a look at the collision matrix at the bottom. Double check that your setup will actually work. \$\endgroup\$ – mr-matt Nov 19 '18 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 '18 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 '18 at 1:14
1
\$\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\$
  • \$\begingroup\$ Your case is OnCollisionEnter(). \$\endgroup\$ – Shitman Nov 16 '18 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\$ – Gabriele Vierti Dec 22 '18 at 10:31
  • \$\begingroup\$ Are you sure? My scene work on sphere collider. \$\endgroup\$ – Shitman Dec 27 '18 at 4:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.