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 | //============================================================================= // Spatial Fear // Name: SFPlane // Description: A vehicle class with plane-like behavior; requires a certain velocity for take-off // // Author: Gert Jen Peltenburg //============================================================================= class SFPlane expands SFVehicle; var (SpatialFear_Plane) float TakeOffSpeed; var (SpatialFear_Plane) float MaxAirSpeed; var float LiftPerSpeedUnit; var (SpatialFear_Plane) float AirAcceleration; var (SpatialFear_Plane) float AirDrag; var (SpatialFear_Plane) bool RudderAvailable; // if not enabled, only rolling will turn the aircraft var bool OnGround; // plane uses look for pitch/roll. Use strafe for rudder control, forward/backward for throttle. simulated function InterpretControls(bool bJustFired,bool bFire,bool bJustAltFired,bool bAltFire, float aVehicleSpeedControl,float aTurretTurn,float aVehicleTurn, float aVehicleUp,float aTurretUp,bool bJustJumped,bool bJustDucked) { if(aVehicleTurn<0) controlinputRoll = (aVehicleTurn/16384.0)*RollLeftRate; else controlinputRoll = (aVehicleTurn/16384.0)*RollRightRate; if(RudderAvailable) { if(aTurretTurn<0) controlinputYaw = (aTurretTurn/16384.0)*YawLeftRate; else controlinputYaw = (aTurretTurn/16384.0)*YawRightRate; } else controlinputYaw=0.0; if(aTurretUp<0) controlinputPitch = (aTurretUp/16384.0)*PitchDownRate; else controlinputPitch = (aTurretUp/16384.0)*PitchUpRate; if(aVehicleSpeedControl<0) // accelerating means pushing the nose down, not up, so inverted ControlInputPitch = -(aVehicleSpeedControl/16384.0)*PitchUpRate; else ControlInputPitch = -(aVehicleSpeedControl/16384.0)*PitchDownRate; DesiredSpeed = Max(0,Min(MaxSpeed,DesiredSpeed+aVehicleUp/16384.0*MaxSpeed)); } // plane only has translational lift (lift through speed). simulated function DoPhysics(float DeltaTime) { local vector force; local vector tempvel,templocation,O,N,HitLocation,HitNormal; local rotator temprot; local actor groundobject; local float lift,drag,acceleration; if(groundfeedbackindex<0) return; PreviousLocation=CurrentLocation; acceleration=Max(DesiredSpeed-CurrentSpeed,0)/MaxSpeed*AirAcceleration; drag=sin(CurrentRotation.Pitch/32768.0*pi)*AirDrag; tempvel=virtuallocation(linearvelocity,rotation); if(passengerof==None) tempvel += virtuallocation(passengerof.velocity,rotation); lift=tempvel.X*LiftPerSpeedUnit; force=RealWorldLocation(vect(0,0,1)*lift*mass,CurrentRotation); // translational lift force+=region.zone.zonegravity*mass; if(!OnGround && tempvel.X< TakeOffSpeed) { // check if we're now on the ground TempLocation = Feedback[groundfeedbackindex].originoffset; TempLocation.X=0; TempLocation.Y=0; TempLocation.Z+=2; N=CurrentLocation+RealWorldLocation(RealWorldLocation(TempLocation,CurrentRotation),planeangles); TempLocation = Feedback[groundfeedbackindex].originoffset; TempLocation.X=0; TempLocation.Y=0; TempLocation.Z-=2; O=CurrentLocation+RealWorldLocation(RealWorldLocation(TempLocation,CurrentRotation),planeangles); if(passengerof!=None) { N=RealWorldLocation(N,passengerof.rotation)+passengerof.location; O=RealWorldLocation(O,passengerof.rotation)+passengerof.location; } groundobject=Trace(HitLocation,HitNormal,O,N,false); while(SFVehicle(groundobject)==Self) { groundobject=Trace(HitLocation,HitNormal,O,HitLocation+normal(O-HitLocation),false); } if(GroundObject!=None && groundobject!=self) OnGround=true; } else { if(tempvel.X>TakeOffSpeed) OnGround=false; } if(OnGround) { super.DoPhysics(deltatime); return; } // From here on, specific plane physics LastGoodLocation=CurrentLocation; LastGoodRotation=CurrentRotation; drag=AirDrag; //sin(CurrentRotation.Pitch/32768*pi)*AirDrag*tempvel.X/MaxSpeed; // the next calculation basically translates the 'percentage' input to a percentage of maxairspeed // so you still choose a speed with you forward axis acceleration=max(0,min(AirAcceleration,max(DesiredSpeed,0)/MaxSpeed*MaxAirSpeed-CurrentSpeed)); LinearVelocity=RealWorldLocation(vect(1,0,0)*CurrentSpeed,currentrotation); CurrentLocation+=(LinearVelocity)*deltatime; CurrentSpeed+=(acceleration-drag)*deltatime; if(CurrentSpeed>MaxAirSpeed) CurrentSpeed=MaxAirSpeed; if(CurrentSpeed<0) CurrentSpeed=0; if(tempvel.X<TakeOffSpeed) {// make sure that lack of lift results in drop LinearVelocity+=force/mass*deltatime; } templocation= VirtualLocation(region.zone.zonegravity,currentrotation)+vect(0,0,1)*lift; temprot=rot(0,0,0); // temprot.pitch=32768.0*atan2(templocation.Z,(CurrentSpeed-TakeOffSpeed))*cos(CurrentRotation.roll/32768.0*pi); temprot.yaw=CurrentSpeed/TakeOffSpeed*sin(CurrentRotation.roll/32768.0*pi)*YawLeftRate*deltatime; // if(temprot.Pitch>physicalrotationrate.pitch*deltatime) // temprot.pitch=physicalrotationrate.pitch*deltatime; if(temprot.Yaw>physicalrotationrate.yaw*deltatime) temprot.yaw=physicalrotationrate.yaw*deltatime; // if(temprot.Pitch<-physicalrotationrate.pitch*deltatime) // temprot.pitch=-physicalrotationrate.pitch*deltatime; if(temprot.Yaw<-physicalrotationrate.yaw*deltatime) temprot.yaw=-physicalrotationrate.yaw*deltatime; // CurrentRotation += temprot; // cap the speed // LinearVelocity=max(1,VSize(LinearVelocity)/MaxAirSpeed)*LinearVelocity; // Check for collision ------- when hitting something, the plane will be damaged! if(CheckForCollision(deltatime)) { CurrentLocation = PreviousLocation; gravityinducedvelocity=vect(0,0,0); CurrentRotation = PreviousRotation; linearvelocity=-linearvelocity; // TakeDamage( ) } } simulated function RotationPhysics(float DeltaTime) { local rotator NewRotation; local float compensationYaw,compensationPitch,compensationRoll; // not using rotator because these values are generally<1 if(DeltaTime<=0) return; if(OnGround) { super.RotationPhysics(DeltaTime); return; } PreviousRotation = CurrentRotation; CurrentRotation.Roll=normalizeangle(CurrentRotation.Roll); CurrentRotation.Pitch=normalizeangle(CurrentRotation.Pitch); CurrentRotation.Yaw=normalizeangle(CurrentRotation.Yaw); NewRotation = CurrentRotation; if(currentcontroller != None) { compensationYaw=ControlInputYaw*deltatime; compensationPitch=ControlInputPitch*deltatime; compensationRoll=ControlInputRoll*deltatime; } NewRotation.Roll += CompensationRoll; NewRotation.Pitch += cos(NewRotation.Roll/32768.0*pi)*compensationPitch-sin(NewRotation.Roll/32768.0*pi)*compensationyaw*airtraction; NewRotation.Yaw += sin(NewRotation.Roll/32768.0*pi)*compensationPitch+cos(NewRotation.Roll/32768.0*pi)*compensationYaw*airtraction; NewRotation.Roll = normalizeangle(NewRotation.Roll); NewRotation.Pitch = normalizeangle(NewRotation.Pitch); NewRotation.Yaw = normalizeangle(NewRotation.Yaw); // if CurrentRotation will change, play rotatingsound CurrentRotation = NewRotation; } simulated function PostBeginPlay() { LiftPerSpeedUnit=VSize(region.zone.zonegravity)/TakeOffSpeed; super.PostBeginPlay(); } defaultproperties { TakeOffSpeed=100.000000 MaxAirSpeed=400.000000 AirAcceleration=150.000000 AirDrag=50.000000 bHUD_ShowsPitch=True bHUD_ShowsYaw=True bHUD_ShowsRoll=True bHUD_ShowsSpeed=True bBot_ShowVehicleLocation=True Armor=50 InitialHitPoints=100 FullHitPoints=100 DestructionEffect=None PhysicalRotationRate=(Pitch=4096,Yaw=4096,Roll=4096) Elasticity=0.000000 bRepairable=False RepairTime=0.000000 bFullTimePhysics=True bDamageTriggered=True } |