internal bool CanBodiesCollide(RigidBody body1, RigidBody body2)
        {
            if (body1.disabled || body2.disabled || !physicsManager.IsCollisionEnabled(body1, body2))
            {
                return(false);
            }

            if (body1.IsStaticNonKinematic && body2.IsStaticNonKinematic)
            {
                return(false);
            }

            bool anyBodyColliderOnly = body1.IsColliderOnly || body2.IsColliderOnly;

            if (anyBodyColliderOnly)
            {
                if ((body1.IsColliderOnly && body1.IsStaticNonKinematic && body2.IsStaticNonKinematic) || (body2.IsColliderOnly && body2.IsStaticNonKinematic && body1.IsStaticNonKinematic))
                {
                    return(false);
                }
            }
            else
            {
                if ((body1.isKinematic && body2.isStatic) || (body2.isKinematic && body1.isStatic))
                {
                    return(false);
                }
            }

            return(true);
        }
示例#2
0
        public static bool IsCollisionEnabled(IBody i_RigidBody1, IBody i_RigidBody2)
        {
            if (m_Instance != null)
            {
                return(m_Instance.IsCollisionEnabled(i_RigidBody1, i_RigidBody2));
            }

            return(false);
        }
示例#3
0
        /**
         * @brief Check collision conditions to follow Unity's guidelines.
         *
         * @return False if bodies should not collide.
         **/
        public static bool CheckCollisionConditions(Fixture fixtureA, Fixture fixtureB)
        {
            Body body1 = fixtureA.Body;
            Body body2 = fixtureB.Body;

            if (body1.disabled || body2.disabled || !physicsManager.IsCollisionEnabled(body1, body2))
            {
                return(false);
            }

            bool body1IsSpecialSensor = body1._specialSensor != BodySpecialSensor.None;
            bool body2IsSpecialSensor = body2._specialSensor != BodySpecialSensor.None;

            if (body1IsSpecialSensor || body2IsSpecialSensor)
            {
                if (body1IsSpecialSensor)
                {
                    int body2Layer = 1 << physicsManager.GetBodyLayer(body2);

                    if ((body1.SpecialSensorMask & body2Layer) != body2Layer)
                    {
                        return(false);
                    }
                }
                else
                {
                    int body1Layer = 1 << physicsManager.GetBodyLayer(body1);

                    if ((body2.SpecialSensorMask & body1Layer) != body1Layer)
                    {
                        return(false);
                    }
                }

                return(true);
            }

            if (body1.IsStatic && body2.IsStatic)
            {
                return(false);
            }

            bool anyBodyColliderOnly = fixtureA.IsSensor || fixtureB.IsSensor;

            if (!anyBodyColliderOnly)
            {
                if (body1.IsKinematic && body2.IsKinematic || (body1.IsKinematic && body2.IsStatic) || (body2.IsKinematic && body1.IsStatic))
                {
                    return(false);
                }
            }

            return(true);
        }