I search for solutions in this order: Past Code, Unreal Source, Wiki, BUF, groups.yahoo, google, screaming at monitor. – RegularX

Legacy:Amphibious Vehicle

From Unreal Wiki, The Unreal Engine Documentation Site
Jump to: navigation, search

By UT2004Addict

http://www.arclength.net/ut2004

Based off of the Hellbender, here's the easiest way to make an Amphibious vehicle (that I've found...)

class Demo extends ONSPRV;
 
 
var float UprightStiffness, UprightDamping;
 
 
 
simulated function PostBeginPlay()
{
 
    super.PostBeginPlay();
 
    // Make sure we float
    KarmaParams(KParams).KBuoyancy = Buoyancy;
 
 
}
 
 
simulated function Tick(float DeltaTime)
{
 
 
    // Handle water stuff
    if (  PhysicsVolume.bWaterVolume
    &&    (Vect(0,0,-1) >> Rotation) dot PhysicsVolume.Gravity > 0    )
    {
        // Try to stay upright if we're not flipped over already
        KSetStayUpright(true, true);
        KSetStayUprightParams(UprightStiffness, UprightDamping);
    }
    else
    {
        // Allow to flip
        KSetStayUpright(false, false);
        KSetStayUprightParams(0, 0);
    }
 
 
 
    super.Tick(DeltaTime);
 
}
 
 
// Instead of using this to take damage,
// we're going to use this to keep
// our vehicle afloat
event TakeWaterDamage(float DeltaTime)
{
 
    local vector TempVector;
 
 
    // Don't drive up or down...
    TempVector = vector(Rotation);
    TempVector.Z = 0.0;
 
 
    if (Throttle != 0)
        KAddImpulse(TempVector * Throttle * 500000.0 * DeltaTime, Location);
 
 
    if (Steering != 0)
        KAddAngularImpulse((vect(0,0,1) >> Rotation) * Steering * Throttle * (-15.0) * DeltaTime);
 
 
}
 
 
defaultproperties
{
 
    Buoyancy=1.5
 
    UprightStiffness=500
    UprightDamping=500
 
    WaterSpeed=1000.0
 
    WaterMovementState=PlayerDriving
 
 
}