NWH Vehicle Physics 2
Search Results for

    Show / Hide Table of Contents

    Class FlipOverModule

    Detects and corrects vehicle rollovers via automatic or manual recovery. Instant mode teleports upright immediately; Gradual mode uses physics-based rotation. Only activates when angle exceeds threshold, velocity is low, and timeout has elapsed.

    Inheritance
    object
    VehicleComponent
    FlipOverModule
    Inherited Members
    VehicleComponent.state
    VehicleComponent.vehicleController
    VehicleComponent.IsActive
    VehicleComponent.VC_Initialize(VehicleController)
    VehicleComponent.VC_Initialize()
    VehicleComponent.VC_FixedUpdate(float)
    VehicleComponent.VC_SetDefaults()
    VehicleComponent.VC_LoadStateFromStateSettings()
    VehicleComponent.VC_Update(float)
    VehicleComponent.VC_DrawGizmos()
    VehicleComponent.VC_Validate(VehicleController)
    VehicleComponent.UpdateLOD()
    VehicleComponent.ToggleState()
    Namespace: NWH.VehiclePhysics2.Modules.FlipOver
    Assembly: NWH.VehiclePhysics2.dll
    Syntax
    [Serializable]
    public class FlipOverModule : VehicleComponent

    Fields

    allowedAngle

    Minimum angle from upright position (in degrees) required to trigger flip detection.

    Declaration
    [Tooltip("Minimum angle that the vehicle needs to be at for it to be detected as flipped over.")]
    public float allowedAngle
    Field Value
    Type Description
    float
    Remarks

    Measured as the angle between the vehicle's up vector and world up (opposite of gravity direction). The vehicle is considered flipped when this angle exceeds the threshold and velocity conditions are met.

    Recommended values: - 45-60°: Aggressive detection, triggers on steep banking (may false-positive) - 70-80°: Balanced detection, allows extreme lean (default: 70°) - 90-120°: Conservative detection, only triggers when significantly inverted

    Lower values provide earlier detection but may trigger during legitimate maneuvers like extreme cornering, hillclimbing, or two-wheel driving. Higher values require more complete rollovers but ensure no false positives.

    Tuning Guidelines: - Off-road vehicles: 80-90° (more tolerant of uneven terrain) - Street vehicles: 70-80° (balanced) - Stunt vehicles: 100-120° (only trigger when completely inverted)

    flipOverActivation

    Determines when flip-over recovery is activated.

    Declaration
    public FlipOverModule.FlipOverActivation flipOverActivation
    Field Value
    Type Description
    FlipOverModule.FlipOverActivation
    Remarks
    • Manual: Player must press the flip-over input (typically 'T' key) to recover
    • Automatic: Recovery begins automatically after timeout when flipped

    flipOverDuration

    Gradual flip animation duration in seconds. Only for Gradual mode. 2-3s: quick (arcade), 4-6s: balanced (default: 5), 7-10s: realistic (sim).

    Declaration
    [Tooltip("How long the flip over process will take if using gradual flip over.")]
    public float flipOverDuration
    Field Value
    Type Description
    float

    flipOverType

    Instant: teleport upright immediately (arcade). Gradual: smooth physics rotation (sim).

    Declaration
    [Tooltip("Determines how the vehicle will be flipped over.")]
    public FlipOverModule.FlipOverType flipOverType
    Field Value
    Type Description
    FlipOverModule.FlipOverType

    flippedOver

    True when angle > allowedAngle and velocities are below maxDetectionSpeed. Can be used to display UI prompts or trigger other systems.

    Declaration
    [Tooltip("Is the vehicle flipped over?")]
    public bool flippedOver
    Field Value
    Type Description
    bool

    instantFlipOverVerticalOffset

    Vertical offset (m) added during Instant flip to prevent ground clipping. Small vehicles: 0.5-1m. Standard cars: 1-2m (default: 1). Large vehicles: 2-3m. Set to ~half vehicle height. Not used for Gradual mode.

    Declaration
    [Tooltip("If using instant (not gradual) flip over this value will be applied to the transform.y position to prevent rotating\r\nthe object to a position that is underground.")]
    public float instantFlipOverVerticalOffset
    Field Value
    Type Description
    float

    maxDetectionSpeed

    Velocity threshold (m/s) for flip detection. Both linear and angular velocity must be below this. 0.2-0.5: strict (sim), 0.6-1.0: balanced (default: 0.6), 1.5-3.0: lenient (arcade).

    Declaration
    [Tooltip("Flip over detection will be disabled if velocity is above this value [m/s].")]
    public float maxDetectionSpeed
    Field Value
    Type Description
    float

    timeout

    Detection check interval and automatic activation delay in seconds.

    Declaration
    [Tooltip("Time after detecting flip over after which vehicle will be flipped back or the manual button can be used.")]
    public float timeout
    Field Value
    Type Description
    float
    Remarks

    Serves dual purpose: 1. Check interval: How often the module checks if vehicle is flipped (performance) 2. Auto-activation delay: Time to wait after flip detection before automatic recovery

    Recommended values: - 0.5-1.0s: Quick response for arcade games (default: 1s) - 1.5-3.0s: Balanced for most games - 3.0-5.0s: Realistic delay for simulation games

    Benefits of delay: - Gives players time to potentially self-recover through momentum - Prevents premature activation while vehicle is still rolling - Allows physics to settle before recovery begins - Reduces frequency of checks for better performance

    Drawbacks of delay: - Players must wait before recovery (potential frustration) - May increase time lost in competitive scenarios

    For manual activation, this creates a "cooldown" - the player cannot spam the flip input and must wait for the timeout between attempts.

    Balance between responsiveness and preventing false positives based on game style.

    Methods

    VC_Disable(bool)

    Disables the component and stops updates. Override to add component-specific disable logic.

    Declaration
    public override bool VC_Disable(bool calledByParent)
    Parameters
    Type Name Description
    bool calledByParent

    True if called by parent component or LOD system

    Returns
    Type Description
    bool

    True if successfully disabled, false otherwise

    Overrides
    VehicleComponent.VC_Disable(bool)
    Remarks

    Component must be initialized before it can be disabled. Tracks whether disable was called by parent to manage LOD system interaction.

    VC_Enable(bool)

    Enables the component and starts updates. Override to add component-specific enable logic.

    Declaration
    public override bool VC_Enable(bool calledByParent)
    Parameters
    Type Name Description
    bool calledByParent

    True if called by parent component or LOD system

    Returns
    Type Description
    bool

    True if successfully enabled, false otherwise

    Overrides
    VehicleComponent.VC_Enable(bool)
    Remarks

    Will initialize the component if not already initialized. Components disabled by LOD system will track the parent caller to prevent manual enabling while LOD is controlling state.

    In this article
    Back to top Copyright © NWH - Vehicle Physics, Aerodynamics, Dynamic Water Physics