Ejemplo n.º 1
0
        private void CreateBody(Physics2D.World world)
        {
            Physics2D.Body body = Physics2D.BodyFactory.CreateBody(world);

            if (tsMaterial == null)
            {
                tsMaterial = GetComponent <TSMaterial>();
            }

            Physics2D.Shape shape = Shape;
            if (shape != null)
            {
                CreateBodyFixture(body, shape);
            }
            else
            {
                Physics2D.Shape[] shapes = CreateShapes();
                for (int index = 0, length = shapes.Length; index < length; index++)
                {
                    CreateBodyFixture(body, shapes[index]);
                }
            }

            if (tsRigidBody == null)
            {
                body.BodyType = Physics2D.BodyType.Static;
            }
            else
            {
                if (tsRigidBody.isKinematic)
                {
                    body.BodyType = TrueSync.Physics2D.BodyType.Kinematic;
                }
                else
                {
                    body.BodyType      = Physics2D.BodyType.Dynamic;
                    body.IgnoreGravity = !tsRigidBody.useGravity;
                }

                if (tsRigidBody.mass <= 0)
                {
                    tsRigidBody.mass = 1;
                }

                body.FixedRotation = tsRigidBody.freezeZAxis;
                body.Mass          = tsRigidBody.mass;
                body.TSLinearDrag  = tsRigidBody.drag;
                body.TSAngularDrag = tsRigidBody.angularDrag;
            }

            body.IsSensor     = isTrigger;
            body.CollidesWith = Physics2D.Category.All;

            _body = body;
        }
Ejemplo n.º 2
0
        private void CreateBody(Physics2D.World world)
        {
            Physics2D.Body    body    = Physics2D.BodyFactory.CreateBody(world);
            Physics2D.Fixture fixture = body.CreateFixture(Shape);

            if (tsMaterial == null)
            {
                tsMaterial = GetComponent <TSMaterial>();
            }

            if (tsMaterial != null)
            {
                fixture.Friction    = tsMaterial.friction;
                fixture.Restitution = tsMaterial.restitution;
            }

            if (tsRigidBody == null)
            {
                body.BodyType = Physics2D.BodyType.Static;
            }
            else
            {
                if (tsRigidBody.isKinematic)
                {
                    body.BodyType = TrueSync.Physics2D.BodyType.Kinematic;
                }
                else
                {
                    body.BodyType      = Physics2D.BodyType.Dynamic;
                    body.IgnoreGravity = !tsRigidBody.useGravity;
                }

                if (tsRigidBody.mass <= 0)
                {
                    tsRigidBody.mass = 1;
                }

                body.FixedRotation = tsRigidBody.freezeZAxis;
                body.Mass          = tsRigidBody.mass;
                body.TSLinearDrag  = tsRigidBody.drag;
                body.TSAngularDrag = tsRigidBody.angularDrag;
            }

            body.IsSensor     = isTrigger;
            body.CollidesWith = Physics2D.Category.All;

            _body = body;
        }
Ejemplo n.º 3
0
        private void CreateBody()
        {
            RigidBody newBody = new RigidBody(Shape);

            if (tsMaterial == null)
            {
                tsMaterial = GetComponent <TSMaterial>();
            }

            if (tsMaterial != null)
            {
                newBody.TSFriction    = tsMaterial.friction;
                newBody.TSRestitution = tsMaterial.restitution;
            }

            newBody.IsColliderOnly = isTrigger;
            newBody.IsKinematic    = tsRigidBody != null && tsRigidBody.isKinematic;

            bool isStatic = tsRigidBody == null || tsRigidBody.isKinematic;

            if (tsRigidBody != null)
            {
                newBody.AffectedByGravity = tsRigidBody.useGravity;

                if (tsRigidBody.mass <= 0)
                {
                    tsRigidBody.mass = 1;
                }

                newBody.Mass          = tsRigidBody.mass;
                newBody.TSLinearDrag  = tsRigidBody.drag;
                newBody.TSAngularDrag = tsRigidBody.angularDrag;
            }
            else
            {
                newBody.SetMassProperties();
            }

            if (isStatic)
            {
                newBody.AffectedByGravity = false;
                newBody.IsStatic          = true;
            }


            _body = newBody;
        }
        private void CreateBody(Physics2D.World i_World)
        {
            Physics2D.Body body = Physics2D.BodyFactory.CreateBody(i_World);

            // Get collision/restitution data from physics material.

            FP materialFriction    = FP.Zero;
            FP materialRestitution = FP.Zero;

            if (m_PhysicsMaterial != null)
            {
                materialFriction    = m_PhysicsMaterial.friction;
                materialRestitution = m_PhysicsMaterial.restitution;
            }
            else
            {
                // Check for a TSMaterial2D. Note: this is deprecated.

                m_TSMaterial = GetComponent <TSMaterial>();

                if (m_TSMaterial != null)
                {
                    materialFriction    = m_TSMaterial.friction;
                    materialRestitution = m_TSMaterial.restitution;
                }
            }

            // Create collision shape(s).

            Physics2D.Shape shape = CreateShape();
            if (shape != null)
            {
                CreateBodyFixture(body, shape, materialFriction, materialRestitution);
            }
            else
            {
                Physics2D.Shape[] shapes = CreateShapes();
                for (int index = 0, length = shapes.Length; index < length; index++)
                {
                    CreateBodyFixture(body, shapes[index], materialFriction, materialRestitution);
                }
            }

            // Setup RigidBody.

            if (m_TSRigidBody == null)
            {
                body.BodyType = Physics2D.BodyType.Static;
            }
            else
            {
                if (m_TSRigidBody.isKinematic)
                {
                    body.BodyType = Physics2D.BodyType.Kinematic;
                }
                else
                {
                    body.BodyType      = Physics2D.BodyType.Dynamic;
                    body.IgnoreGravity = !m_TSRigidBody.useGravity;
                }

                if (m_TSRigidBody.mass <= 0)
                {
                    m_TSRigidBody.mass = 1;
                }

                body.FixedRotation = m_TSRigidBody.freezeZAxis;
                body.Mass          = m_TSRigidBody.mass;

                body.TSLinearDrag  = m_TSRigidBody.linearDrag;
                body.TSAngularDrag = m_TSRigidBody.angularDrag;
            }

            m_Body  = body;
            m_Shape = shape;

            SetIsSensor(m_IsTrigger);
            SetCollisionLayer(gameObject.layer);
        }