diff --git a/Client/Common.cs b/Client/Common.cs index 8870978..6b28365 100644 --- a/Client/Common.cs +++ b/Client/Common.cs @@ -187,7 +187,7 @@ public static Vector3 GetEntityTopCoords(int entity) return coords; } - public static void ApplyTorque(int entity, float x, float y, bool scaleLeverage = true) + public static void ApplyTorque(int entity, float pitch, float roll, float yaw, bool scaleLeverage = true) { var min = -Vector3.One; var max = Vector3.One; @@ -199,16 +199,22 @@ public static void ApplyTorque(int entity, float x, float y, bool scaleLeverage API.GetModelDimensions(model, ref min, ref max); } - if (x != 0) // up-down + if (pitch != 0) { - API.ApplyForceToEntity(entity, 1, 0f, 0f, x, 0f, max.Y, 0f, -1, true, true, true, false, false); - API.ApplyForceToEntity(entity, 1, 0f, 0f, -x, 0f, min.Y, 0f, -1, true, true, true, false, false); + API.ApplyForceToEntity(entity, 1, 0f, 0f, pitch, 0f, max.Y, 0f, -1, true, true, true, false, false); + API.ApplyForceToEntity(entity, 1, 0f, 0f, -pitch, 0f, min.Y, 0f, -1, true, true, true, false, false); } - if (y != 0) // left-right + if (roll != 0) { - API.ApplyForceToEntity(entity, 1, 0f, 0f, y, max.X, 0f, 0f, -1, true, true, true, false, false); - API.ApplyForceToEntity(entity, 1, 0f, 0f, -y, min.X, 0f, 0f, -1, true, true, true, false, false); + API.ApplyForceToEntity(entity, 1, 0f, 0f, roll, max.X, 0f, 0f, -1, true, true, true, false, false); + API.ApplyForceToEntity(entity, 1, 0f, 0f, -roll, min.X, 0f, 0f, -1, true, true, true, false, false); + } + + if (yaw != 0) + { + API.ApplyForceToEntity(entity, 1, 0f, yaw, 0f, max.X, 0f, 0f, -1, true, true, true, false, false); + API.ApplyForceToEntity(entity, 1, 0f, -yaw, 0f, min.X, 0f, 0f, -1, true, true, true, false, false); } } @@ -322,6 +328,15 @@ public static Vector3 DirectionToRotation(Vector3 dir) return new Vector3((float)pitch, 0f, (float)yaw); } + public static float GetAngleDifference(float a, float b, bool deg = true) + { + var pi = deg ? 180f : (float)Math.PI; + //return pi - Math.Abs(Math.Abs(a - b) - pi); + + var diff = a - b; + return diff > pi ? diff - (2 * pi) : diff; + } + public static Vector3 GetRandomSpawnCoordsInRange(Vector3 center, float minRange, float maxRange, out float heading) { heading = API.GetRandomFloatInRange(0f, 360f); diff --git a/Client/Vehicles.cs b/Client/Vehicles.cs index 4f819f9..b0f0aa1 100644 --- a/Client/Vehicles.cs +++ b/Client/Vehicles.cs @@ -66,10 +66,12 @@ public enum Light private static readonly int TurboBoostKey; private static readonly int TurboBoostHorizontalKey; private static readonly int TurboBoostVerticalKey; - private static readonly int StabilizerKey; private static readonly int[] RemoteControlKeys = new int[] { 172, 173, 174, 175 }; + private static readonly int StabilizerKey; + private static readonly bool StabilizerHeadingLock; private static float _stabilizerPitch; private static float _stabilizerRoll; + private static float _stabilizerYaw; static Vehicles() { @@ -77,6 +79,7 @@ static Vehicles() TurboBoostHorizontalKey = Config.GetConfigInt("TurboBoostHorizontalKey"); TurboBoostVerticalKey = Config.GetConfigInt("TurboBoostVerticalKey"); StabilizerKey = Config.GetConfigInt("StabilizerKey"); + StabilizerHeadingLock = Config.GetConfigBool("StabilizerHeadingLock"); } public Vehicles() @@ -733,12 +736,14 @@ private static Task UpdateControls() { _stabilizerPitch = API.GetEntityPitch(vehicle); _stabilizerRoll = API.GetEntityRoll(vehicle); + _stabilizerYaw = API.GetEntityHeading(vehicle); } else if (API.IsControlPressed(0, StabilizerKey)) { var pitch = _stabilizerPitch - API.GetEntityPitch(vehicle); var roll = _stabilizerRoll - API.GetEntityRoll(vehicle); - Common.ApplyTorque(vehicle, pitch * 0.1f, roll * 0.1f); + var yaw = StabilizerHeadingLock ? Common.GetAngleDifference(_stabilizerYaw, API.GetEntityHeading(vehicle)) : 0f; + Common.ApplyTorque(vehicle, pitch * 0.02f, roll * 0.02f, yaw * 0.01f); } } @@ -751,19 +756,23 @@ private static Task UpdateControls() if (API.IsPedInFlyingVehicle(driver)) { + var pitch = 0f; + var roll = 0f; var model = (uint)API.GetEntityModel(vehicle); var isHeli = API.IsThisModelAHeli(model); var force = isHeli ? 0.1f : 1f; if (API.IsControlPressed(0, 172)) // up - Common.ApplyTorque(vehicle, -force, 0); + pitch = -force; else if (API.IsControlPressed(0, 173)) // down - Common.ApplyTorque(vehicle, force, 0); + pitch = force; if (API.IsControlPressed(0, 174)) // left - Common.ApplyTorque(vehicle, 0, force / 2); + roll = force / 2; else if (API.IsControlPressed(0, 175)) // right - Common.ApplyTorque(vehicle, 0, -force / 2); + roll = -force / 2; + + Common.ApplyTorque(vehicle, pitch, roll, 0); if (isHeli) API.TaskVehicleTempAction(driver, vehicle, 9, 1); diff --git a/config/config.ini b/config/config.ini index 86f2aa0..90afa02 100644 --- a/config/config.ini +++ b/config/config.ini @@ -24,6 +24,7 @@ TurboBoostVerticalKey=21 TurboBrakePower=400.0 TurboBrakeMinSpeed=3.0 StabilizerKey=36 +StabilizerHeadingLock=true EnableTelemetry=true ; Permissions: