Engines - NeisesMike/VehicleFramework GitHub Wiki
Your vehicle's engine controls the way your vehicle moves.
Overview
ModVehicle has the field:
public virtual ModVehicleEngine Engine { get; set; }
Your vehicle will be given an engine if you don't set one here.
ModVehicleEngine Class
But let's look at the ModVehicleEngine class anyway. These are perhaps its most important virtual fields.
public abstract class ModVehicleEngine : MonoBehaviour
{
...
// change these to alter the top speed in the given direction
protected virtual float FORWARD_TOP_SPEED => 1000;
protected virtual float REVERSE_TOP_SPEED => 1000;
protected virtual float STRAFE_MAX_SPEED => 1000;
protected virtual float VERT_MAX_SPEED => 1000;
// change these to alter the acceleration in the given direction
protected virtual float FORWARD_ACCEL => FORWARD_TOP_SPEED / 10f;
protected virtual float REVERSE_ACCEL => REVERSE_TOP_SPEED / 10f;
protected virtual float STRAFE_ACCEL => STRAFE_MAX_SPEED / 10f;
protected virtual float VERT_ACCEL => VERT_MAX_SPEED / 10f;
// change this to alter how quickly the vehicle comes to a stop
protected virtual float waterDragDecay => 4.5f;
public virtual void ControlRotation()
{
if (mv.GetIsUnderwater() || CanRotateAboveWater)
{
// Control rotation
float pitchFactor = 1.4f; // change this to make looking up and down easier or harder
float yawFactor = 1.4f; // change this to make looking left and right easier or harder
Vector2 mouseDir = GameInput.GetLookDelta();
float xRot = mouseDir.x;
float yRot = mouseDir.y;
rb.AddTorque(mv.transform.up * xRot * yawFactor * Time.deltaTime, ForceMode.VelocityChange);
rb.AddTorque(mv.transform.right * yRot * -pitchFactor * Time.deltaTime, ForceMode.VelocityChange);
}
}
public virtual void DrainPower(Vector3 moveDirection)
{
float scalarFactor = 1.0f; // change this to make the vehicle more or less power hungry
float basePowerConsumptionPerSecond = moveDirection.x + moveDirection.y + moveDirection.z;
float upgradeModifier = Mathf.Pow(0.85f, mv.numEfficiencyModules);
mv.GetComponent<PowerManager>().TrySpendEnergy(scalarFactor * basePowerConsumptionPerSecond * upgradeModifier * Time.deltaTime);
}
...
}
Vehicle Framework Examples
See a few examples of engines used in Vehicle Framework.
Aircraft Library
For more examples, see AircraftLib.
AircraftLib adds several engines specifically for aircraft.