Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation
previous class next class | frames no frames

# Gameplay.Car

00001 00002 00003 00004 00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257

    // Car

    // Base Tribes 4-wheeled vehicle class. Effectively a copy past of KCar.
    class Car extends Vehicle
    	native
        abstract
    	notplaceable;

    var (Car) float StopThreshold; // forward velocity under which brakes become drive

    var (Car) float upsideDownDamagePerSecond;

    // moved this up from HavokCar because it is used in processInput
    var (HavokVehicleGeneral) float	SteeringMaxAngle;  // unreal units

    var (Car) float strafeSteerAngleOffset;

    var int Gear; // 1 is forward, -1 is backward, currently symmetric power/torque curve

    // effect states
    var bool effectDeccelerating;
    var bool effectAccelerating;

    var int outputCarDirection;

    var float carSteer;

    ////////// NAVIGATION //////////

    var float stopSteeringSize;
    var float stopVelocitySize;
    var float driveThrottleCoefficient;
    var float maximumYawChange;
    var float minimumNavigationThrottle;

    simulated event PostNetBeginPlay()
    {
        Super.PostNetBeginPlay();

    	// initially make sure parameters are sync'ed with Karma
    	VehicleUpdateParams();
    }

    simulated function tick(float deltaSeconds)
    {
    	super.tick(deltaSeconds);

    	// do upside down damage processing

    	// The PHYS_None check prevents this code from running after the game ends.

    	if (Level.NetMode != NM_Client && bSettledUpsideDown && Physics != PHYS_None)
    	{
    		TakeDamage(deltaSeconds * upsideDownDamagePerSecond, self, Location, vect(0,0,0), class'DamageType');
    	}
    }

    function ProcessInput()
    {
    	super.processInput();

    	// steering
    	outputCarDirection = Normalize(rotationInput).yaw;
    	if (outputCarDirection < 0)
    		outputCarDirection += 65536;
    }

    simulated function updateGear()
    {
    	local float ForwardVel;
    	local bool bIsInverted;

    	local vector worldForward, worldUp;

    	worldForward = vect(1, 0, 0) >> Rotation;
    	worldUp = vect(0, 0, 1) >> Rotation;

    	ForwardVel = Velocity Dot worldForward;

    	bIsInverted = worldUp.Z < 0.2;

    	// 'ForwardVel' isn't very helpful if we are inverted, so we just pretend its positive.
    	if (bIsInverted)
    		ForwardVel = 2 * StopThreshold;

    	if (clientPositions[driverIndex].occupant == None)
    	{
    		Gear = 0;
    	}
    	else
    	{
    		if (ThrottleInput > 0.01) // pressing forwards
    		{
    			if (ForwardVel < -StopThreshold && Gear != 1) // going backwards - so brake first
    			{
    				if (effectAccelerating)
    				{
    					UnTriggerEffectEvent('CarAccelerating');
    					effectAccelerating = false;
    				}
    				if (!effectDeccelerating)
    				{
    					TriggerEffectEvent('CarDeccelerating');
    					effectDeccelerating = true;
    				}

    				Gear = 0;
    			}
    			else // stopped or going forwards, so drive
    			{
    				if (effectDeccelerating)
    				{
    					UnTriggerEffectEvent('CarDeccelerating');
    					effectDeccelerating = false;
    				}
    				if (!effectAccelerating)
    				{
    					TriggerEffectEvent('CarAccelerating');
    					effectAccelerating = true;
    				}

    				Gear = 1;
    			}
    		}
    		else if (ThrottleInput < -0.01) // pressing backwards
    		{
    			if (ForwardVel < StopThreshold) // start going backwards
    			{
    				if (effectDeccelerating)
    				{
    					UnTriggerEffectEvent('CarDeccelerating');
    					effectDeccelerating = false;
    				}
    				if (!effectAccelerating)
    				{
    					TriggerEffectEvent('CarAccelerating');
    					effectAccelerating = true;
    				}

    				Gear = -1;
    			}
    			else // otherwise, we are going forwards, or still holding brake, so just brake
    			{
    				if (effectAccelerating)
    				{
    					UnTriggerEffectEvent('CarAccelerating');
    					effectAccelerating = false;
    				}
    				if (!effectDeccelerating)
    				{
    					TriggerEffectEvent('CarDeccelerating');
    					effectDeccelerating = true;
    				}

    				Gear = 0;
    			}
    		}
    		else // not pressing either
    		{
    			// do nothing
    		}
    	}
    }

    simulated function applyOutput()
    {
    	local rotator steeringDirection;
    	local vector inputDirection;
    	local vector carDirection;

    	local vector workVector;
    	local rotator workRotator;

    	local float steerAngle;

    	updateGear();

    	// steering
    	steeringDirection.yaw = outputCarDirection;

    	// ... user input direction
    	inputDirection = vect(1,0,0) >> steeringDirection;
    	inputDirection.Z = 0;
    	inputDirection = Normal(inputDirection);

    	// ... apply strafe offset
    	if (StrafeInput != 0)
    	{
    		workRotator.Pitch = 0;
    		workRotator.Roll = 0;
    		if (StrafeInput > 0)
    			workRotator.Yaw = -strafeSteerAngleOffset;
    		else if (StrafeInput < 0)
    			workRotator.Yaw = strafeSteerAngleOffset;
    		inputDirection = inputDirection >> workRotator;
    	}

    	// ... current car direction
    	carDirection = vect(1,0,0) >> rotation;
    	carDirection.Z = 0;
    	carDirection = Normal(carDirection);

    	// ... desired steer angle
    	steerAngle = acos(inputDirection dot carDirection);
    	steerAngle *= 65536 / (2 * PI);
    	steerAngle = clamp(steerAngle, 0, SteeringMaxAngle);
    	workVector = inputDirection cross carDirection;
    	if (workVector.Z < 0)
    		steerAngle *= -1;
    	if (gear == -1)
    		steerAngle *= -1;

    	steerAngle = clamp(steerAngle, -SteeringMaxAngle, SteeringMaxAngle);

    	if (positions[driverIndex].occupant == None)
    	{
    		steerAngle = 0;
    	}

    	// ... actual car steer value
    	carSteer = steerAngle / SteeringMaxAngle;
    }

    // Clean up wheels etc.
    simulated event Destroyed()
    {
    	UnTriggerEffectEvent('CarAccelerating');
    	UnTriggerEffectEvent('CarDeccelerating');

    	Super.Destroyed();
    }

    defaultproperties
    {
    	Gear=1

    //	WheelVert=-0.5

    	StopThreshold=100

    	effectDeccelerating=false
    	effectAccelerating=false

    	stopSteeringSize=50
    	stopVelocitySize=50
    	driveThrottleCoefficient=0.09
    	driveYawCoefficient=0.05
    	maximumYawChange=450

    	SteeringMaxAngle = 20000

    	upsideDownDamagePerSecond = 100

    	strafeSteerAngleOffset = 8192

    	minimumNavigationThrottle = -1
    }

Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation
previous class next class | frames no frames

Class file time: ne 5.9.2004 15:53:28.000 - Creation time: st 23.5.2018 00:10:42.652 - Created with UnCodeX