public override void ExclusiveUpdate() { if (Human.HasChute()) { entity.ModifyLinearDamping(0.8f); } if (Human.HasJetpack()) { if (Human.JPBoost) { if (!Human.ConsumeFuel(Delta * 3.5)) // TODO: Custom fuel consumption per-item! { return; } double max; double boost = Human.JetpackBoostRate(out max); double glen; Vector3 move = GetMoveVector(out glen); Vector3 vec = -(move * (double)boost) * Delta; Human.CBody.Jump(); Entity.ApplyLinearImpulse(ref vec); if (Entity.LinearVelocity.LengthSquared() > max * max) { Vector3 vel = entity.LinearVelocity; vel.Normalize(); Entity.LinearVelocity = vel * max; } } else if (Human.JPHover) { if (!Human.ConsumeFuel(Delta)) // TODO: Custom fuel consumption per-item! { return; } double hover = Human.JetpackHoverStrength(); double glen; Vector3 move = GetMoveVector(out glen); Vector3 vec = -(move * (double)glen * (double)hover) * Delta; Entity.ApplyLinearImpulse(ref vec); entity.ModifyLinearDamping(0.6f); } } }
public override void ExclusiveUpdate() { if (Helicopter.DriverSeat.Sitter == null) { return; // Don't fly when there's nobody driving this! } // Collect the helicopter's relative "up" vector Vector3 up = Quaternion.Transform(Vector3.UnitZ, Entity.Orientation); // Apply the amount of force necessary to counteract downward force, within a limit. // POTENTIAL: Adjust according to orientation? double uspeed = Math.Min(Helicopter.LiftStrength, -(Entity.LinearVelocity.Z + Entity.Space.ForceUpdater.Gravity.Z) * Entity.Mass); if (uspeed < 0f) { uspeed += (uspeed - Helicopter.FallStrength) * Helicopter.SprintOrWalk; } else { uspeed += (Helicopter.LiftStrength - uspeed) * Helicopter.SprintOrWalk; } Vector3 upvel = up * uspeed * Delta; Entity.ApplyLinearImpulse(ref upvel); // Rotate slightly to move in a direction. // At the same time, fight against existing rotation. Vector3 VecUp = new Vector3(Helicopter.RightLeft * 0.2f * Helicopter.TiltMod, Helicopter.ForwBack * -0.2f * Helicopter.TiltMod, 1); // TODO: Simplify yawrel calculation. double tyaw = (double)(Utilities.MatrixToAngles(Matrix.CreateFromQuaternion(Entity.Orientation)).Z *Utilities.PI180); Quaternion yawrel = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, tyaw); VecUp = Quaternion.Transform(VecUp, yawrel); VecUp.Y = -VecUp.Y; VecUp.Normalize(); Vector3 axis = Vector3.Cross(VecUp, up); double len = axis.Length(); if (len > 0) { axis /= len; double angle = (double)Math.Asin(len); if (!double.IsNaN(angle)) { double avel = Vector3.Dot(Entity.AngularVelocity, axis); Vector3 torque = axis * ((-angle) - 0.3f * avel); torque *= Entity.Mass * Delta * 30; Entity.ApplyAngularImpulse(ref torque); } } // Spin in place double rotation = (Helicopter.IRight ? -1f : 0f) + (Helicopter.ILeft ? 1f : 0f); if (rotation * rotation > 0f) { Vector3 rot = new Vector3(0, 0, rotation * 15f * Delta * Entity.Mass); Entity.ApplyAngularImpulse(ref rot); } // Apply air drag Entity.ModifyLinearDamping(0.3f); // TODO: arbitrary constant Entity.ModifyAngularDamping(0.6f); // TODO: arbitrary constant // Ensure we're active if flying! Entity.ActivityInformation.Activate(); }