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

            if (FPMaterial == null)
            {
                FPMaterial = GetComponent <FPMaterial>();
            }

            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 (FPRigidBody == null)
            {
                body.BodyType = Physics2D.BodyType.Static;
            }
            else
            {
                if (FPRigidBody.isKinematic)
                {
                    body.BodyType = Spax.Physics2D.BodyType.Kinematic;
                }
                else
                {
                    body.BodyType      = Physics2D.BodyType.Dynamic;
                    body.IgnoreGravity = !FPRigidBody.useGravity;
                }

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

                body.FixedRotation = FPRigidBody.freezeZAxis;
                body.Mass          = FPRigidBody.mass;
                body.FPLinearDrag  = FPRigidBody.drag;
                body.FPAngularDrag = FPRigidBody.angularDrag;
            }

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

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

            if (FPMaterial == null)
            {
                FPMaterial = GetComponent <FPMaterial>();
            }

            if (FPMaterial != null)
            {
                newBody.FPFriction    = FPMaterial.friction;
                newBody.FPRestitution = FPMaterial.restitution;
            }

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

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

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

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

                newBody.Mass          = FPRigidBody.mass;
                newBody.FPLinearDrag  = FPRigidBody.drag;
                newBody.FPAngularDrag = FPRigidBody.angularDrag;
            }
            else
            {
                newBody.SetMassProperties();
            }

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

            _body = newBody;
        }