Skip to content

Commit

Permalink
Improved Flying Cars
Browse files Browse the repository at this point in the history
- Use actual flying controls
- Lose speed over time
  • Loading branch information
Regynate committed Jan 21, 2025
1 parent 8cdd7fc commit 55cc048
Showing 1 changed file with 48 additions and 25 deletions.
73 changes: 48 additions & 25 deletions ChaosMod/Effects/db/Vehs/VehsFlyingCar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,60 @@ static void OnTick()
if (IS_PED_IN_ANY_VEHICLE(player, 0))
{
Vehicle veh = GET_VEHICLE_PED_IS_IN(player, 0);

int vehClass = GET_VEHICLE_CLASS(veh);
if (vehClass == 15 || vehClass == 16)
return;

Vector3 vec = GET_ENTITY_FORWARD_VECTOR(veh);
float currentSpeed = GET_ENTITY_SPEED(veh);
float maxSpeed = GET_VEHICLE_MODEL_ESTIMATED_MAX_SPEED(GET_ENTITY_MODEL(veh));
if (currentSpeed < maxSpeed * 0.6)
float forwardSpeed = GET_ENTITY_SPEED_VECTOR(veh, true).y;

if (currentSpeed < maxSpeed * 0.3f)
return;
if (IS_CONTROL_PRESSED(0, 71)) // Forward
SET_VEHICLE_FORWARD_SPEED(veh, std::min(maxSpeed * 3.f, currentSpeed + 0.3f));

if (vehClass == 14 || !IS_VEHICLE_ON_ALL_WHEELS(veh)) // Allow Steering if not "on ground" or boat in water
{
Vector3 rot = GET_ENTITY_ROTATION(veh, 2);
if (IS_CONTROL_PRESSED(0, 63)) // Turn Left
rot.z += 1.0;
if (IS_CONTROL_PRESSED(0, 64)) // Turn Right
rot.z -= 1.0;

if (IS_CONTROL_PRESSED(0, 108)) // Roll Left
rot.y -= 1.0;

if (IS_CONTROL_PRESSED(0, 109)) // Roll Right
rot.y += 1.0;

if (IS_CONTROL_PRESSED(0, 111)) // Tilt Down
rot.x -= 1.0;

if (IS_CONTROL_PRESSED(0, 112)) // Tilt Up
rot.x += 1.0;
SET_ENTITY_ROTATION(veh, rot.x, rot.y, rot.z, 2, 1);
}

float deltaSpeed = 10.f * GET_FRAME_TIME();
Vector3 vel = GET_ENTITY_VELOCITY(veh);

DISABLE_CONTROL_ACTION(1, 68, true); // Aim
DISABLE_CONTROL_ACTION(1, 69, true); // Attack

if (IS_CONTROL_PRESSED(0, 87)) // Forward
vel = vec * (currentSpeed + deltaSpeed);
else if (IS_CONTROL_PRESSED(0, 88)) // Brake
vel = vec * (currentSpeed - deltaSpeed);
else if (forwardSpeed >= maxSpeed * 0.8f)
vel = vec * (currentSpeed - deltaSpeed * 0.2f);

float length = VMAG(vel.x, vel.y, vel.x);

if (length > maxSpeed * 3.f)
vel = vel * (maxSpeed * 3.f / length);

SET_ENTITY_VELOCITY(veh, vel.x, vel.y, vel.z);

float deltaAngle = 100.f * GET_FRAME_TIME();

Vector3 rot = GET_ENTITY_ROTATION(veh, 2);

if (IS_CONTROL_PRESSED(0, 89)) // Turn Left
rot.z += deltaAngle;
if (IS_CONTROL_PRESSED(0, 90)) // Turn Right
rot.z -= deltaAngle;

if (IS_CONTROL_PRESSED(0, 108)) // Roll Left
rot.y -= deltaAngle;

if (IS_CONTROL_PRESSED(0, 109)) // Roll Right
rot.y += deltaAngle;

if (IS_CONTROL_PRESSED(0, 111)) // Tilt Down
rot.x -= deltaAngle;

if (IS_CONTROL_PRESSED(0, 112)) // Tilt Up
rot.x += deltaAngle;
SET_ENTITY_ROTATION(veh, rot.x, rot.y, rot.z, 2, 1);
}
}

Expand Down

0 comments on commit 55cc048

Please sign in to comment.