private void UpdateLocalFromInput() { // if (racer.shipPhysics.shipNearGround()) // { if (chosenInput.actionPressed(InputAction.Backwards)) { racer.shipPhysics.applyImpulseInSurfacePlane(racer.shipPhysics.racerEntity.OrientationMatrix.Backward * 100); } //axis*angle*factor*analogueInputFactor //Apply left/right rotation multiplied by analogue steering values //keyboard keys have analogue values of 0f when up and 1f when pressed. //Only apply rotation if the ship doesn't already have a large rotational force Vector3 a = Vector3.Up; Vector3 b = racer.shipPhysics.racerEntity.BufferedStates.Entity.AngularVelocity; float angularSize = Vector3.Dot(a, b); // Change the impulse direction if we are in reverse int reversingMultiplier = 1; //if (new Random().Next(60) == 0) Console.WriteLine(angularSize); // CAUTION: We change reverse direction once we're reversing more than 35f. Plays better when hitting walls head on but weird. float backwardsComponent = Vector3.Dot(racer.shipPhysics.racerEntity.LinearVelocity, racer.shipPhysics.racerEntity.WorldTransform.Backward); if (backwardsComponent > 20f) { reversingMultiplier = -1; } if (backwardsComponent != 0f) { if (angularSize < 3.5f) { Vector3 leftVector = racer.shipPhysics.racerEntity.OrientationMatrix.Up * reversingMultiplier * 105f * (1 + (Math.Abs(angularSize) * 0.12f)) * chosenInput.getActionValue(InputAction.Left); Physics.ApplyAngularImpulse(ref leftVector, racer.shipPhysics.racerEntity); } if (angularSize > -3.5f) { Vector3 rightVector = racer.shipPhysics.racerEntity.OrientationMatrix.Up * reversingMultiplier * -105f * (1 + (Math.Abs(angularSize) * 0.12f)) * chosenInput.getActionValue(InputAction.Right); Physics.ApplyAngularImpulse(ref rightVector, racer.shipPhysics.racerEntity); } } }