private void CreateBody(Physics2D.World world)
        {
            Physics2D.Body body = Physics2D.BodyFactory.CreateBody(world);

            if (tsMaterial == null)
            {
                tsMaterial = 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 = KBEngine.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.TSLinearDrag  = FPRigidBody.drag;
                body.TSAngularDrag = FPRigidBody.angularDrag;
            }

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

            _body = body;
        }
Beispiel #2
0
        private void CreateBody()
        {
            RigidBody newBody = new RigidBody(Shape);

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

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

            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.TSLinearDrag  = FPRigidBody.drag;
                newBody.TSAngularDrag = FPRigidBody.angularDrag;
            }
            else
            {
                newBody.SetMassProperties();
            }

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

            _body = newBody;
        }