public override void Load() { // Ground body Body ground; { ground = Physics.NewBody(m_world); // outline Physics.NewFixture(ground, Physics.NewChainShape(true, new Vector2[] { new Vector2(0.0f, -2.0f), new Vector2(8.0f, 6.0f), new Vector2(8.0f, 20.0f), new Vector2(-8.0f, 20.0f), new Vector2(-8.0f, 6.0f), }), 0); } // Flippers { var p1 = new Vector2(-2.0f, 0.0f); var p2 = new Vector2(2.0f, 0.0f); Body leftFlipper = Physics.NewBody(m_world, p1.X, p1.Y, BodyType.Dynamic); Body rightFlipper = Physics.NewBody(m_world, p2.X, p2.Y, BodyType.Dynamic); var box = Physics.NewRectangleShape(1.75f * 2, 0.1f * 2); Physics.NewFixture(leftFlipper, box, 1.0f); Physics.NewFixture(rightFlipper, box, 1.0f); lrj = Physics.NewRevoluteJoint(ground, leftFlipper, p1); lrj.SetMotorSpeed(0); lrj.SetMotorEnabled(true); lrj.SetLimitsEnabled(true); lrj.SetMaxMotorTorque(1000.0f); lrj.SetLimits(-30.0f * Mathf.PI / 180.0f, 5.0f * Mathf.PI / 180.0f); rrj = Physics.NewRevoluteJoint(ground, rightFlipper, p2); rrj.SetMotorSpeed(0); rrj.SetMotorEnabled(true); rrj.SetLimitsEnabled(true); rrj.SetMaxMotorTorque(1000.0f); rrj.SetLimits(-5.0f * Mathf.PI / 180.0f, 30.0f * Mathf.PI / 180.0f); } // Circle character { var body = Physics.NewBody(m_world, 1.0f, 15.0f, BodyType.Dynamic); body.SetBullet(true); Physics.NewFixture(body, Physics.NewCircleShape(0.2f), 1.0f); } }
public Ragdoll(World world, Vector2 position) { // Physics // Head _head = world.CreateCircle(0.75f, 10f); _head.BodyType = BodyType.Dynamic; _head.AngularDamping = LimbAngularDamping; _head.Mass = 2f; _head.Position = position; // Torso _upperBody = world.CreateCapsule(0.5f, 0.75f, LegDensity); _upperBody.BodyType = BodyType.Dynamic; _upperBody.Mass = 1f; _upperBody.SetTransform(position + new Vector2(0f, -1.75f), -MathHelper.Pi / 2f); _middleBody = world.CreateCapsule(0.5f, 0.75f, LegDensity); _middleBody.BodyType = BodyType.Dynamic; _middleBody.Mass = 1f; _middleBody.SetTransform(position + new Vector2(0f, -3f), -MathHelper.Pi / 2f); _lowerBody = world.CreateCapsule(0.5f, 0.75f, LegDensity); _lowerBody.BodyType = BodyType.Dynamic; _lowerBody.Mass = 1f; _lowerBody.SetTransform(position + new Vector2(0f, -4.25f), -MathHelper.Pi / 2f); // Left Arm _lowerLeftArm = world.CreateCapsule(1f, 0.45f, ArmDensity); _lowerLeftArm.BodyType = BodyType.Dynamic; _lowerLeftArm.AngularDamping = LimbAngularDamping; _lowerLeftArm.Mass = 2f; _lowerLeftArm.Rotation = -1.4f; _lowerLeftArm.Position = position + new Vector2(-4f, -2.2f); _upperLeftArm = world.CreateCapsule(1f, 0.45f, ArmDensity); _upperLeftArm.BodyType = BodyType.Dynamic; _upperLeftArm.AngularDamping = LimbAngularDamping; _upperLeftArm.Mass = 2f; _upperLeftArm.Rotation = -1.4f; _upperLeftArm.Position = position + new Vector2(-2f, -1.8f); // Right Arm _lowerRightArm = world.CreateCapsule(1f, 0.45f, ArmDensity); _lowerRightArm.BodyType = BodyType.Dynamic; _lowerRightArm.AngularDamping = LimbAngularDamping; _lowerRightArm.Mass = 2f; _lowerRightArm.Rotation = 1.4f; _lowerRightArm.Position = position + new Vector2(4f, -2.2f); _upperRightArm = world.CreateCapsule(1f, 0.45f, ArmDensity); _upperRightArm.BodyType = BodyType.Dynamic; _upperRightArm.AngularDamping = LimbAngularDamping; _upperRightArm.Mass = 2f; _upperRightArm.Rotation = 1.4f; _upperRightArm.Position = position + new Vector2(2f, -1.8f); // Left Leg _lowerLeftLeg = world.CreateCapsule(1f, 0.5f, LegDensity); _lowerLeftLeg.BodyType = BodyType.Dynamic; _lowerLeftLeg.AngularDamping = LimbAngularDamping; _lowerLeftLeg.Mass = 2f; _lowerLeftLeg.Position = position + new Vector2(-0.6f, -8f); _upperLeftLeg = world.CreateCapsule(1f, 0.5f, LegDensity); _upperLeftLeg.BodyType = BodyType.Dynamic; _upperLeftLeg.AngularDamping = LimbAngularDamping; _upperLeftLeg.Mass = 2f; _upperLeftLeg.Position = position + new Vector2(-0.6f, -6f); // Right Leg _lowerRightLeg = world.CreateCapsule(1f, 0.5f, LegDensity); _lowerRightLeg.BodyType = BodyType.Dynamic; _lowerRightLeg.AngularDamping = LimbAngularDamping; _lowerRightLeg.Mass = 2f; _lowerRightLeg.Position = position + new Vector2(0.6f, -8f); _upperRightLeg = world.CreateCapsule(1f, 0.5f, LegDensity); _upperRightLeg.BodyType = BodyType.Dynamic; _upperRightLeg.AngularDamping = LimbAngularDamping; _upperRightLeg.Mass = 2f; _upperRightLeg.Position = position + new Vector2(0.6f, -6f); // head -> upper body DistanceJoint jointHeadBody = new DistanceJoint(_head, _upperBody, new Vector2(0f, -1f), new Vector2(-0.75f, 0f)); jointHeadBody.CollideConnected = true; jointHeadBody.DampingRatio = DampingRatio; jointHeadBody.Frequency = Frequency; jointHeadBody.Length = 0.025f; world.Add(jointHeadBody); // lowerLeftArm -> upperLeftArm DistanceJoint jointLeftArm = new DistanceJoint(_lowerLeftArm, _upperLeftArm, new Vector2(0f, 1f), new Vector2(0f, -1f)); jointLeftArm.CollideConnected = true; jointLeftArm.DampingRatio = DampingRatio; jointLeftArm.Frequency = Frequency; jointLeftArm.Length = 0.02f; world.Add(jointLeftArm); // upperLeftArm -> upper body DistanceJoint jointLeftArmBody = new DistanceJoint(_upperLeftArm, _upperBody, new Vector2(0f, 1f), new Vector2(-0.15f, -1f)); jointLeftArmBody.DampingRatio = DampingRatio; jointLeftArmBody.Frequency = Frequency; jointLeftArmBody.Length = 0.02f; world.Add(jointLeftArmBody); // lowerRightArm -> upperRightArm DistanceJoint jointRightArm = new DistanceJoint(_lowerRightArm, _upperRightArm, new Vector2(0f, 1f), new Vector2(0f, -1f)); jointRightArm.CollideConnected = true; jointRightArm.DampingRatio = DampingRatio; jointRightArm.Frequency = Frequency; jointRightArm.Length = 0.02f; world.Add(jointRightArm); // upperRightArm -> upper body DistanceJoint jointRightArmBody = new DistanceJoint(_upperRightArm, _upperBody, new Vector2(0f, 1f), new Vector2(-0.15f, 1f)); jointRightArmBody.DampingRatio = DampingRatio; jointRightArmBody.Frequency = 25; jointRightArmBody.Length = 0.02f; world.Add(jointRightArmBody); // lowerLeftLeg -> upperLeftLeg DistanceJoint jointLeftLeg = new DistanceJoint(_lowerLeftLeg, _upperLeftLeg, new Vector2(0f, 1.1f), new Vector2(0f, -1f)); jointLeftLeg.CollideConnected = true; jointLeftLeg.DampingRatio = DampingRatio; jointLeftLeg.Frequency = Frequency; jointLeftLeg.Length = 0.05f; world.Add(jointLeftLeg); // upperLeftLeg -> lower body DistanceJoint jointLeftLegBody = new DistanceJoint(_upperLeftLeg, _lowerBody, new Vector2(0f, 1.1f), new Vector2(0.7f, -0.8f)); jointLeftLegBody.CollideConnected = true; jointLeftLegBody.DampingRatio = DampingRatio; jointLeftLegBody.Frequency = Frequency; jointLeftLegBody.Length = 0.02f; world.Add(jointLeftLegBody); // lowerRightleg -> upperRightleg DistanceJoint jointRightLeg = new DistanceJoint(_lowerRightLeg, _upperRightLeg, new Vector2(0f, 1.1f), new Vector2(0f, -1f)); jointRightLeg.CollideConnected = true; jointRightLeg.DampingRatio = DampingRatio; jointRightLeg.Frequency = Frequency; jointRightLeg.Length = 0.05f; world.Add(jointRightLeg); // upperRightleg -> lower body DistanceJoint jointRightLegBody = new DistanceJoint(_upperRightLeg, _lowerBody, new Vector2(0f, 1.1f), new Vector2(0.7f, 0.8f)); jointRightLegBody.CollideConnected = true; jointRightLegBody.DampingRatio = DampingRatio; jointRightLegBody.Frequency = Frequency; jointRightLegBody.Length = 0.02f; world.Add(jointRightLegBody); // upper body -> middle body RevoluteJoint jointUpperTorso = new RevoluteJoint(_upperBody, _middleBody, _upperBody.Position + new Vector2(0f, -0.625f), true); jointUpperTorso.LimitEnabled = true; jointUpperTorso.SetLimits(MathHelper.Pi / 16f, -MathHelper.Pi / 16f); world.Add(jointUpperTorso); // middle body -> lower body RevoluteJoint jointLowerTorso = new RevoluteJoint(_middleBody, _lowerBody, _middleBody.Position + new Vector2(0f, -0.625f), true); jointLowerTorso.LimitEnabled = true; jointLowerTorso.SetLimits(MathHelper.Pi / 8f, -MathHelper.Pi / 8f); world.Add(jointLowerTorso); // GFX _face = new Sprite(ContentWrapper.CircleTexture(0.75f, "Square", ContentWrapper.Gold, ContentWrapper.Orange, ContentWrapper.Grey, 1f, 24f)); _torso = new Sprite(ContentWrapper.PolygonTexture(PolygonTools.CreateRoundedRectangle(1.5f, 2f, 0.75f, 0.75f, 2), "Stripe", ContentWrapper.Gold, ContentWrapper.Orange, ContentWrapper.Black, 2.0f, 24f)); _upperLimb = new Sprite(ContentWrapper.PolygonTexture(PolygonTools.CreateCapsule(1.9f, 0.45f, 16), "Square", ContentWrapper.Gold, ContentWrapper.Orange, ContentWrapper.Black, 1f, 24f)); _lowerLimb = new Sprite(ContentWrapper.PolygonTexture(PolygonTools.CreateCapsule(2f, 0.5f, 16), "Square", ContentWrapper.Gold, ContentWrapper.Orange, ContentWrapper.Black, 1f, 24f)); }
public void Update(int ranking_, float steeringValue_ = 0, bool braking_ = false) { // Updates the vehicle // ================ foreach (Tyre t in m_vehicleTyres) { t.UpdateTyre(ranking_, steeringValue_, braking_); t.UpdateFriction(); } foreach (Tyre t in m_vehicleTyres) { t.UpdateDrive(); if (t.IsPowered()) { if (t.GetBody().LinearVelocity.Length() > 3.0f) { GraphicsHandler.StartFireTrail(t.GetPositionDisplay()); } else if (t.GetBody().LinearVelocity.Length() > 2.0f) { GraphicsHandler.StartDriveTrail(t.GetPositionDisplay()); } else if (t.GetBody().LinearVelocity.Length() > 0.0f) { GraphicsHandler.StartBrakeTrail(t.GetPositionDisplay()); } else if (t.GetBody().LinearVelocity.Length() < 0.0f) { GraphicsHandler.StartBrakeTrail(t.GetPositionDisplay()); } } float lockAngle = Util.DegreesToRadians(20); float turnSpeedPerSec = Util.DegreesToRadians(320); float turnPerTimeStep = turnSpeedPerSec / 60; float desiredAngle = steeringValue_ * lockAngle; float angleNow = m_frontLeftJoint.JointAngle; float angleToTurn = desiredAngle - angleNow; angleToTurn = FarseerPhysics.Common.MathUtils.Clamp(angleToTurn, -turnPerTimeStep, turnPerTimeStep); float newAngle = angleNow + angleToTurn; if (desiredAngle > 0.25) { GraphicsHandler.StartSkidMarks(t.GetPositionDisplay()); } m_frontLeftJoint.SetLimits(newAngle, newAngle); m_frontRightJoint.SetLimits(newAngle, newAngle); t.UpdateSprites(); // AUDIO if (!braking_) { carbrake.Stop(); //ADDED go.Play(); // ADDED } else { go.Stop(); //ADDED carbrake.Play(); // ADDED } } Debug.AddText("Body position D: " + FarseerPhysics.ConvertUnits.ToDisplayUnits(m_vehicleBody.GetPosition()).ToString(), new Vector2(10, 300)); Debug.AddText("Body position S: " + m_vehicleBody.GetPosition().ToString(), new Vector2(10, 320)); Debug.AddText("FL position D: " + FarseerPhysics.ConvertUnits.ToDisplayUnits(m_vehicleTyres[0].GetPosition()).ToString(), new Vector2(10, 360)); Debug.AddText("FL position S: " + m_vehicleTyres[0].GetPosition().ToString(), new Vector2(10, 380)); Debug.AddText("FL rotation: " + Util.RadiansToDegrees(m_frontLeftJoint.JointAngle).ToString(), new Vector2(10, 400)); Debug.AddText("FR position D: " + FarseerPhysics.ConvertUnits.ToDisplayUnits(m_vehicleTyres[1].GetPosition()).ToString(), new Vector2(10, 420)); Debug.AddText("FR position S: " + m_vehicleTyres[1].GetPosition().ToString(), new Vector2(10, 440)); Debug.AddText("FR rotation: " + Util.RadiansToDegrees(m_frontRightJoint.JointAngle).ToString(), new Vector2(10, 460)); m_vehicleBody.UpdateSprites(); }
public Ragdoll(World world, Vector2 position) { // Physics // Head _head = BodyFactory.CreateCircle(world, 0.75f, 10f); _head.BodyType = BodyType.Dynamic; _head.AngularDamping = LimbAngularDamping; _head.Mass = 2f; _head.Position = position; // Torso _upperBody = BodyFactory.CreateCapsule(world, 0.5f, 0.75f, LegDensity); _upperBody.BodyType = BodyType.Dynamic; _upperBody.Mass = 1f; _upperBody.SetTransform(position + new Vector2(0f, 1.75f), MathHelper.Pi / 2f); _middleBody = BodyFactory.CreateCapsule(world, 0.5f, 0.75f, LegDensity); _middleBody.BodyType = BodyType.Dynamic; _middleBody.Mass = 1f; _middleBody.SetTransform(position + new Vector2(0f, 3f), MathHelper.Pi / 2f); _lowerBody = BodyFactory.CreateCapsule(world, 0.5f, 0.75f, LegDensity); _lowerBody.BodyType = BodyType.Dynamic; _lowerBody.Mass = 1f; _lowerBody.SetTransform(position + new Vector2(0f, 4.25f), MathHelper.Pi / 2f); // Left Arm _lowerLeftArm = BodyFactory.CreateCapsule(world, 1f, 0.45f, ArmDensity); _lowerLeftArm.BodyType = BodyType.Dynamic; _lowerLeftArm.AngularDamping = LimbAngularDamping; _lowerLeftArm.Mass = 2f; _lowerLeftArm.Rotation = 1.4f; _lowerLeftArm.Position = position + new Vector2(-4f, 2.2f); _upperLeftArm = BodyFactory.CreateCapsule(world, 1f, 0.45f, ArmDensity); _upperLeftArm.BodyType = BodyType.Dynamic; _upperLeftArm.AngularDamping = LimbAngularDamping; _upperLeftArm.Mass = 2f; _upperLeftArm.Rotation = 1.4f; _upperLeftArm.Position = position + new Vector2(-2f, 1.8f); // Right Arm _lowerRightArm = BodyFactory.CreateCapsule(world, 1f, 0.45f, ArmDensity); _lowerRightArm.BodyType = BodyType.Dynamic; _lowerRightArm.AngularDamping = LimbAngularDamping; _lowerRightArm.Mass = 2f; _lowerRightArm.Rotation = -1.4f; _lowerRightArm.Position = position + new Vector2(4f, 2.2f); _upperRightArm = BodyFactory.CreateCapsule(world, 1f, 0.45f, ArmDensity); _upperRightArm.BodyType = BodyType.Dynamic; _upperRightArm.AngularDamping = LimbAngularDamping; _upperRightArm.Mass = 2f; _upperRightArm.Rotation = -1.4f; _upperRightArm.Position = position + new Vector2(2f, 1.8f); // Left Leg _lowerLeftLeg = BodyFactory.CreateCapsule(world, 1f, 0.5f, LegDensity); _lowerLeftLeg.BodyType = BodyType.Dynamic; _lowerLeftLeg.AngularDamping = LimbAngularDamping; _lowerLeftLeg.Mass = 2f; _lowerLeftLeg.Position = position + new Vector2(-0.6f, 8f); _upperLeftLeg = BodyFactory.CreateCapsule(world, 1f, 0.5f, LegDensity); _upperLeftLeg.BodyType = BodyType.Dynamic; _upperLeftLeg.AngularDamping = LimbAngularDamping; _upperLeftLeg.Mass = 2f; _upperLeftLeg.Position = position + new Vector2(-0.6f, 6f); // Right Leg _lowerRightLeg = BodyFactory.CreateCapsule(world, 1f, 0.5f, LegDensity); _lowerRightLeg.BodyType = BodyType.Dynamic; _lowerRightLeg.AngularDamping = LimbAngularDamping; _lowerRightLeg.Mass = 2f; _lowerRightLeg.Position = position + new Vector2(0.6f, 8f); _upperRightLeg = BodyFactory.CreateCapsule(world, 1f, 0.5f, LegDensity); _upperRightLeg.BodyType = BodyType.Dynamic; _upperRightLeg.AngularDamping = LimbAngularDamping; _upperRightLeg.Mass = 2f; _upperRightLeg.Position = position + new Vector2(0.6f, 6f); // head -> upper body DistanceJoint jointHeadBody = new DistanceJoint(_head, _upperBody, new Vector2(0f, 1f), new Vector2(-0.75f, 0f)); jointHeadBody.CollideConnected = true; jointHeadBody.DampingRatio = DampingRatio; jointHeadBody.Frequency = Frequency; jointHeadBody.Length = 0.025f; world.AddJoint(jointHeadBody); // lowerLeftArm -> upperLeftArm DistanceJoint jointLeftArm = new DistanceJoint(_lowerLeftArm, _upperLeftArm, new Vector2(0f, -1f), new Vector2(0f, 1f)); jointLeftArm.CollideConnected = true; jointLeftArm.DampingRatio = DampingRatio; jointLeftArm.Frequency = Frequency; jointLeftArm.Length = 0.02f; world.AddJoint(jointLeftArm); // upperLeftArm -> upper body DistanceJoint jointLeftArmBody = new DistanceJoint(_upperLeftArm, _upperBody, new Vector2(0f, -1f), new Vector2(-0.15f, 1f)); jointLeftArmBody.DampingRatio = DampingRatio; jointLeftArmBody.Frequency = Frequency; jointLeftArmBody.Length = 0.02f; world.AddJoint(jointLeftArmBody); // lowerRightArm -> upperRightArm DistanceJoint jointRightArm = new DistanceJoint(_lowerRightArm, _upperRightArm, new Vector2(0f, -1f), new Vector2(0f, 1f)); jointRightArm.CollideConnected = true; jointRightArm.DampingRatio = DampingRatio; jointRightArm.Frequency = Frequency; jointRightArm.Length = 0.02f; world.AddJoint(jointRightArm); // upperRightArm -> upper body DistanceJoint jointRightArmBody = new DistanceJoint(_upperRightArm, _upperBody, new Vector2(0f, -1f), new Vector2(-0.15f, -1f)); jointRightArmBody.DampingRatio = DampingRatio; jointRightArmBody.Frequency = 25; jointRightArmBody.Length = 0.02f; world.AddJoint(jointRightArmBody); // lowerLeftLeg -> upperLeftLeg DistanceJoint jointLeftLeg = new DistanceJoint(_lowerLeftLeg, _upperLeftLeg, new Vector2(0f, -1.1f), new Vector2(0f, 1f)); jointLeftLeg.CollideConnected = true; jointLeftLeg.DampingRatio = DampingRatio; jointLeftLeg.Frequency = Frequency; jointLeftLeg.Length = 0.05f; world.AddJoint(jointLeftLeg); // upperLeftLeg -> lower body DistanceJoint jointLeftLegBody = new DistanceJoint(_upperLeftLeg, _lowerBody, new Vector2(0f, -1.1f), new Vector2(0.7f, 0.8f)); jointLeftLegBody.CollideConnected = true; jointLeftLegBody.DampingRatio = DampingRatio; jointLeftLegBody.Frequency = Frequency; jointLeftLegBody.Length = 0.02f; world.AddJoint(jointLeftLegBody); // lowerRightleg -> upperRightleg DistanceJoint jointRightLeg = new DistanceJoint(_lowerRightLeg, _upperRightLeg, new Vector2(0f, -1.1f), new Vector2(0f, 1f)); jointRightLeg.CollideConnected = true; jointRightLeg.DampingRatio = DampingRatio; jointRightLeg.Frequency = Frequency; jointRightLeg.Length = 0.05f; world.AddJoint(jointRightLeg); // upperRightleg -> lower body DistanceJoint jointRightLegBody = new DistanceJoint(_upperRightLeg, _lowerBody, new Vector2(0f, -1.1f), new Vector2(0.7f, -0.8f)); jointRightLegBody.CollideConnected = true; jointRightLegBody.DampingRatio = DampingRatio; jointRightLegBody.Frequency = Frequency; jointRightLegBody.Length = 0.02f; world.AddJoint(jointRightLegBody); // upper body -> middle body RevoluteJoint jointUpperTorso = new RevoluteJoint(_upperBody, _middleBody, _upperBody.Position + new Vector2(0f, 0.625f), true); jointUpperTorso.LimitEnabled = true; jointUpperTorso.SetLimits(-MathHelper.Pi / 16f, MathHelper.Pi / 16f); world.AddJoint(jointUpperTorso); // middle body -> lower body RevoluteJoint jointLowerTorso = new RevoluteJoint(_middleBody, _lowerBody, _middleBody.Position + new Vector2(0f, 0.625f), true); jointLowerTorso.LimitEnabled = true; jointLowerTorso.SetLimits(-MathHelper.Pi / 8f, MathHelper.Pi / 8f); world.AddJoint(jointLowerTorso); }
public Ragdoll(World world, Vector2 position) { // Physics // Head _head = BodyFactory.CreateCircle(world, 0.75f, 10f); _head.BodyType = BodyType.Dynamic; _head.AngularDamping = LimbAngularDamping; _head.Mass = 2f; _head.Position = position; // Torso Body = BodyFactory.CreateCapsule(world, 0.5f, 0.75f, LegDensity); Body.BodyType = BodyType.Dynamic; Body.Mass = 1f; Body.SetTransform(position + new Vector2(0f, 1.75f), MathHelper.Pi / 2f); _middleBody = BodyFactory.CreateCapsule(world, 0.5f, 0.75f, LegDensity); _middleBody.BodyType = BodyType.Dynamic; _middleBody.Mass = 1f; _middleBody.SetTransform(position + new Vector2(0f, 3f), MathHelper.Pi / 2f); _lowerBody = BodyFactory.CreateCapsule(world, 0.5f, 0.75f, LegDensity); _lowerBody.BodyType = BodyType.Dynamic; _lowerBody.Mass = 1f; _lowerBody.SetTransform(position + new Vector2(0f, 4.25f), MathHelper.Pi / 2f); // Left Arm _lowerLeftArm = BodyFactory.CreateCapsule(world, 1f, 0.45f, ArmDensity); _lowerLeftArm.BodyType = BodyType.Dynamic; _lowerLeftArm.AngularDamping = LimbAngularDamping; _lowerLeftArm.Mass = 2f; _lowerLeftArm.Rotation = 1.4f; _lowerLeftArm.Position = position + new Vector2(-4f, 2.2f); _upperLeftArm = BodyFactory.CreateCapsule(world, 1f, 0.45f, ArmDensity); _upperLeftArm.BodyType = BodyType.Dynamic; _upperLeftArm.AngularDamping = LimbAngularDamping; _upperLeftArm.Mass = 2f; _upperLeftArm.Rotation = 1.4f; _upperLeftArm.Position = position + new Vector2(-2f, 1.8f); // Right Arm _lowerRightArm = BodyFactory.CreateCapsule(world, 1f, 0.45f, ArmDensity); _lowerRightArm.BodyType = BodyType.Dynamic; _lowerRightArm.AngularDamping = LimbAngularDamping; _lowerRightArm.Mass = 2f; _lowerRightArm.Rotation = -1.4f; _lowerRightArm.Position = position + new Vector2(4f, 2.2f); _upperRightArm = BodyFactory.CreateCapsule(world, 1f, 0.45f, ArmDensity); _upperRightArm.BodyType = BodyType.Dynamic; _upperRightArm.AngularDamping = LimbAngularDamping; _upperRightArm.Mass = 2f; _upperRightArm.Rotation = -1.4f; _upperRightArm.Position = position + new Vector2(2f, 1.8f); // Left Leg _lowerLeftLeg = BodyFactory.CreateCapsule(world, 1f, 0.5f, LegDensity); _lowerLeftLeg.BodyType = BodyType.Dynamic; _lowerLeftLeg.AngularDamping = LimbAngularDamping; _lowerLeftLeg.Mass = 2f; _lowerLeftLeg.Position = position + new Vector2(-0.6f, 8f); _upperLeftLeg = BodyFactory.CreateCapsule(world, 1f, 0.5f, LegDensity); _upperLeftLeg.BodyType = BodyType.Dynamic; _upperLeftLeg.AngularDamping = LimbAngularDamping; _upperLeftLeg.Mass = 2f; _upperLeftLeg.Position = position + new Vector2(-0.6f, 6f); // Right Leg _lowerRightLeg = BodyFactory.CreateCapsule(world, 1f, 0.5f, LegDensity); _lowerRightLeg.BodyType = BodyType.Dynamic; _lowerRightLeg.AngularDamping = LimbAngularDamping; _lowerRightLeg.Mass = 2f; _lowerRightLeg.Position = position + new Vector2(0.6f, 8f); _upperRightLeg = BodyFactory.CreateCapsule(world, 1f, 0.5f, LegDensity); _upperRightLeg.BodyType = BodyType.Dynamic; _upperRightLeg.AngularDamping = LimbAngularDamping; _upperRightLeg.Mass = 2f; _upperRightLeg.Position = position + new Vector2(0.6f, 6f); // head -> upper body DistanceJoint jointHeadBody = new DistanceJoint(_head, Body, new Vector2(0f, 1f), new Vector2(-0.75f, 0f)); JointHelper.LinearStiffness(Frequency, DampingRatio, jointHeadBody.BodyA, jointHeadBody.BodyB, out var stiffness, out var damping); jointHeadBody.CollideConnected = true; jointHeadBody.Damping = damping; jointHeadBody.Stiffness = stiffness; jointHeadBody.Length = 0.025f; world.AddJoint(jointHeadBody); // lowerLeftArm -> upperLeftArm DistanceJoint jointLeftArm = new DistanceJoint(_lowerLeftArm, _upperLeftArm, new Vector2(0f, -1f), new Vector2(0f, 1f)); JointHelper.LinearStiffness(Frequency, DampingRatio, jointLeftArm.BodyA, jointLeftArm.BodyB, out stiffness, out damping); jointLeftArm.CollideConnected = true; jointLeftArm.Damping = damping; jointLeftArm.Stiffness = stiffness; jointLeftArm.Length = 0.02f; world.AddJoint(jointLeftArm); // upperLeftArm -> upper body DistanceJoint jointLeftArmBody = new DistanceJoint(_upperLeftArm, Body, new Vector2(0f, -1f), new Vector2(-0.15f, 1f)); JointHelper.LinearStiffness(Frequency, DampingRatio, jointLeftArmBody.BodyA, jointLeftArmBody.BodyB, out stiffness, out damping); jointLeftArmBody.Damping = damping; jointLeftArmBody.Stiffness = stiffness; jointLeftArmBody.Length = 0.02f; world.AddJoint(jointLeftArmBody); // lowerRightArm -> upperRightArm DistanceJoint jointRightArm = new DistanceJoint(_lowerRightArm, _upperRightArm, new Vector2(0f, -1f), new Vector2(0f, 1f)); JointHelper.LinearStiffness(Frequency, DampingRatio, jointRightArm.BodyA, jointRightArm.BodyB, out stiffness, out damping); jointRightArm.CollideConnected = true; jointRightArm.Damping = damping; jointRightArm.Stiffness = stiffness; jointRightArm.Length = 0.02f; world.AddJoint(jointRightArm); // upperRightArm -> upper body DistanceJoint jointRightArmBody = new DistanceJoint(_upperRightArm, Body, new Vector2(0f, -1f), new Vector2(-0.15f, -1f)); JointHelper.LinearStiffness(Frequency, DampingRatio, jointRightArmBody.BodyA, jointRightArmBody.BodyB, out stiffness, out damping); jointRightArmBody.Damping = damping; jointRightArmBody.Stiffness = stiffness; jointRightArmBody.Length = 0.02f; world.AddJoint(jointRightArmBody); // lowerLeftLeg -> upperLeftLeg DistanceJoint jointLeftLeg = new DistanceJoint(_lowerLeftLeg, _upperLeftLeg, new Vector2(0f, -1.1f), new Vector2(0f, 1f)); JointHelper.LinearStiffness(Frequency, DampingRatio, jointLeftLeg.BodyA, jointLeftLeg.BodyB, out stiffness, out damping); jointLeftLeg.CollideConnected = true; jointLeftLeg.Damping = damping; jointLeftLeg.Stiffness = stiffness; jointLeftLeg.Length = 0.05f; world.AddJoint(jointLeftLeg); // upperLeftLeg -> lower body DistanceJoint jointLeftLegBody = new DistanceJoint(_upperLeftLeg, _lowerBody, new Vector2(0f, -1.1f), new Vector2(0.7f, 0.8f)); JointHelper.LinearStiffness(Frequency, DampingRatio, jointLeftLegBody.BodyA, jointLeftLegBody.BodyB, out stiffness, out damping); jointLeftLegBody.CollideConnected = true; jointLeftLegBody.Damping = damping; jointLeftLegBody.Stiffness = stiffness; jointLeftLegBody.Length = 0.02f; world.AddJoint(jointLeftLegBody); // lowerRightleg -> upperRightleg DistanceJoint jointRightLeg = new DistanceJoint(_lowerRightLeg, _upperRightLeg, new Vector2(0f, -1.1f), new Vector2(0f, 1f)); JointHelper.LinearStiffness(Frequency, DampingRatio, jointRightLeg.BodyA, jointRightLeg.BodyB, out stiffness, out damping); jointRightLeg.CollideConnected = true; jointRightLeg.Damping = damping; jointRightLeg.Stiffness = stiffness; jointRightLeg.Length = 0.05f; world.AddJoint(jointRightLeg); // upperRightleg -> lower body DistanceJoint jointRightLegBody = new DistanceJoint(_upperRightLeg, _lowerBody, new Vector2(0f, -1.1f), new Vector2(0.7f, -0.8f)); JointHelper.LinearStiffness(Frequency, DampingRatio, jointRightLegBody.BodyA, jointRightLegBody.BodyB, out stiffness, out damping); jointRightLegBody.CollideConnected = true; jointRightLegBody.Damping = damping; jointRightLegBody.Stiffness = stiffness; jointRightLegBody.Length = 0.02f; world.AddJoint(jointRightLegBody); // upper body -> middle body RevoluteJoint jointUpperTorso = new RevoluteJoint(Body, _middleBody, Body.Position + new Vector2(0f, 0.625f), true); jointUpperTorso.LimitEnabled = true; jointUpperTorso.SetLimits(-MathHelper.Pi / 16f, MathHelper.Pi / 16f); world.AddJoint(jointUpperTorso); // middle body -> lower body RevoluteJoint jointLowerTorso = new RevoluteJoint(_middleBody, _lowerBody, _middleBody.Position + new Vector2(0f, 0.625f), true); jointLowerTorso.LimitEnabled = true; jointLowerTorso.SetLimits(-MathHelper.Pi / 8f, MathHelper.Pi / 8f); world.AddJoint(jointLowerTorso); // GFX _face = new Sprite(Managers.TextureManager.CircleTexture(0.75f, "Square", Colors.Gold, Colors.Orange, Colors.Grey, 1f)); _torso = new Sprite(Managers.TextureManager.PolygonTexture(PolygonUtils.CreateRoundedRectangle(1.5f, 2f, 0.75f, 0.75f, 2), "Stripe", Colors.Gold, Colors.Orange, Colors.Black, 2.0f)); _upperLimb = new Sprite(Managers.TextureManager.PolygonTexture(PolygonUtils.CreateCapsule(1.9f, 0.45f, 16), "Square", Colors.Gold, Colors.Orange, Colors.Black, 1f)); _lowerLimb = new Sprite(Managers.TextureManager.PolygonTexture(PolygonUtils.CreateCapsule(2f, 0.5f, 16), "Square", Colors.Gold, Colors.Orange, Colors.Black, 1f)); }