public override void ExclusiveUpdate() { if (Character.HasChute()) { entity.ModifyLinearDamping(0.8f); } if (Character.HasJetpack() && Character.HasFuel) { if (Character.JPBoost) { double boost = Character.JetpackBoostRate(out float max); Vector3 move = GetMoveVector(out double glen); Vector3 vec = -(move * boost) * Delta; Character.CBody.Jump(); Entity.ApplyLinearImpulse(ref vec); if (Entity.LinearVelocity.LengthSquared() > max * max) { Vector3 vel = entity.LinearVelocity; vel.Normalize(); Entity.LinearVelocity = vel * max; } Character.DoJetpackEffect(10); } else if (Character.JPHover) { double hover = Character.JetpackHoverStrength(); Vector3 move = GetMoveVector(out double glen); Vector3 vec = -(move * glen * hover) * Delta; Entity.ApplyLinearImpulse(ref vec); entity.ModifyLinearDamping(0.6f); Character.DoJetpackEffect(3); } } }
public override void ExclusiveUpdate() { if (Helicopter.HeloPilot == null) { return; // Don't fly when there's nobody driving this! } // Collect the helicopter's relative "up" vector BEPUutilities.Vector3 up = BEPUutilities.Quaternion.Transform(BEPUutilities.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.HeloPilot.SprintOrWalk; } else { uspeed += (Helicopter.LiftStrength - uspeed) * Helicopter.HeloPilot.SprintOrWalk; } BEPUutilities.Vector3 upvel = up * uspeed * Delta; Entity.ApplyLinearImpulse(ref upvel); // Rotate slightly to move in a direction. // At the same time, fight against existing rotation. BEPUutilities.Vector3 VecUp = new BEPUutilities.Vector3(Helicopter.HeloPilot.XMove * 0.2f * Helicopter.HeloTiltMod, Helicopter.HeloPilot.YMove * -0.2f * Helicopter.HeloTiltMod, 1); // TODO: Simplify yawrel calculation. float tyaw = (float)(Utilities.MatrixToAngles(Matrix.CreateFromQuaternion(Entity.Orientation)).Z * Utilities.PI180); BEPUutilities.Quaternion yawrel = BEPUutilities.Quaternion.CreateFromAxisAngle(BEPUutilities.Vector3.UnitZ, tyaw); VecUp = BEPUutilities.Quaternion.Transform(VecUp, yawrel); VecUp.Normalize(); VecUp.Y = -VecUp.Y; BEPUutilities.Vector3 axis = BEPUutilities.Vector3.Cross(VecUp, up); double len = axis.Length(); if (len > 0) { axis /= len; float angle = (float)Math.Asin(len); if (!float.IsNaN(angle)) { double avel = BEPUutilities.Vector3.Dot(Entity.AngularVelocity, axis); BEPUutilities.Vector3 torque = axis * ((-angle) - 0.3f * avel); torque *= Entity.Mass * Delta * 30; Entity.ApplyAngularImpulse(ref torque); } } // Spin in place float rotation = (Helicopter.HeloPilot.ItemRight ? -1f : 0f) + (Helicopter.HeloPilot.ItemLeft ? 1f : 0f); if (rotation * rotation > 0f) { BEPUutilities.Vector3 rot = new BEPUutilities.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(); }