Duality.Components.Physics.RigidBody.AddJoint C# (CSharp) Method

AddJoint() public method

Adds a new joint to the Collider
public AddJoint ( Duality.Components.Physics.JointInfo joint, RigidBody other = null ) : void
joint Duality.Components.Physics.JointInfo
other RigidBody
return void
        public void AddJoint(JointInfo joint, RigidBody other = null)
        {
            if (joint == null) throw new ArgumentNullException("joint");

            if (joint.BodyA != null)		joint.BodyA.RemoveJoint(joint);
            else if (joint.BodyB != null)	joint.BodyB.RemoveJoint(joint);

            joint.BodyA = this;
            joint.BodyB = other;

            if (joint.BodyA != null)
            {
                if (joint.BodyA.joints == null) joint.BodyA.joints = new List<JointInfo>();
                joint.BodyA.joints.Add(joint);
                joint.BodyA.AwakeBody();
            }
            if (joint.BodyB != null)
            {
                if (joint.BodyB.joints == null) joint.BodyB.joints = new List<JointInfo>();
                joint.BodyB.joints.Add(joint);
                joint.BodyB.AwakeBody();
            }

            joint.UpdateJoint();
        }

Usage Example

示例#1
0
        private void SetupFrictionJoint(RigidBody body)
        {
            // If we already have a friction joint, is it connecting the right bodies?
            if (this.frictionJoint != null)
            {
                if (this.frictionJoint.ParentBody != body ||
                    this.frictionJoint.ParentBody != this.baseObject)
                {
                    this.frictionJoint.ParentBody.RemoveJoint(this.frictionJoint);
                    this.frictionJoint = null;
                }
            }

            // Create a friction joint connecting our body to the body it is standing on
            if (this.frictionJoint == null)
            {
                this.frictionJoint = new FrictionJointInfo();
                this.frictionJoint.CollideConnected = true;
                this.frictionJoint.MaxTorque = 0.0f;
                body.AddJoint(this.frictionJoint, this.baseObject);
            }
        }