Announcement

Collapse

The Infinity Blade Forums Have Moved

We've launched brand new Infinity Blade forums with improved features and revamped layout. We've also included a complete archive of the previous posts. Come check out the new Infinity Blade forums.
See more
See less

[Code] Aeroplane Man

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    [Code] Aeroplane Man

    hello

    heres a very simple 'aeroplane' script.
    'D' and 'A' - Thrust
    Arrows or Mouse - Steer/Pitch



    Tegleg_PlaneController.uc
    Code:
    class Tegleg_PlaneController extends UTPlayerController;
    
    var float Thrust;
    var Rotator ViewRotation;
    
    simulated function PostBeginPlay()
    {
    	Super.PostBeginPlay();
    
    	SetCameraMode('ThirdPerson');
    }
    
    state PlayerWalking
    {
    ignores SeePlayer, HearNoise, Bump;
    
    	function PlayerMove(float DeltaTime)
    	{
    		local vector X,Y,Z;
              //`Log("!!!controller state WALKING : playermove !!!!!!!!!!!!!!!!!!!!!!!!");
    		GetAxes(Rotation,X,Y,Z);
    
            //forward thrust
    		Pawn.Acceleration = Thrust*X;
    		Pawn.Acceleration = Pawn.AccelRate * Normal(Pawn.Acceleration);
    
    		// Update rotation.
    		UpdateRotation( DeltaTime );
    
    		if ( Role < ROLE_Authority ) // then save this move and replicate it
    			ReplicateMove(DeltaTime, Pawn.Acceleration, DCLICK_None, rot(0,0,0));
    		else
    			ProcessMove(DeltaTime, Pawn.Acceleration, DCLICK_None, rot(0,0,0));
    	}
    
    	event BeginState(Name PreviousStateName)
    	{
    		Pawn.SetPhysics(PHYS_Flying);
    	}
    }
    
    //flight code///////////////////////////
    function UpdateRotation( float DeltaTime )
    {
    	local Rotator TempRotationP, TempRotationRoll, TempWorldRotationRoll;
    
    	ViewRotation = Rotation;
    	if (Pawn != None)
    	{
    		Pawn.SetDesiredRotation(ViewRotation);
    	}
    
    	//forward thrust
    	if ((PlayerInput.aStrafe > 0) && (Thrust < 5000))
    	{Thrust += 50;}
    
    	if ((PlayerInput.aStrafe < 0) && (Thrust > 0))
    	{Thrust -= 50;}
    
    	/////// ROTATION ////////////////
    
        //Roll
    	if (PlayerInput.aTurn > 0)
    	{
        ViewRotation.Yaw += 100;
        TempWorldRotationRoll = WorldInfo.Rotation;
        TempWorldRotationRoll.Roll += 10000;
        TempRotationRoll = RInterpTo(Rotation, TempWorldRotationRoll, DeltaTime, 1.0);
        ViewRotation.Roll = TempRotationRoll.Roll;
        }
    
    	if (PlayerInput.aTurn < 0)
    	{
        ViewRotation.Yaw -= 100;
        TempWorldRotationRoll = WorldInfo.Rotation;
        TempWorldRotationRoll.Roll -= 10000;
        TempRotationRoll = RInterpTo(Rotation, TempWorldRotationRoll, DeltaTime, 1.0);
        ViewRotation.Roll = TempRotationRoll.Roll;
        }
    
    	 //level out roll when no turn input
    	 if (PlayerInput.aTurn == 0)
    	{
          if(ViewRotation.Roll != 0) ViewRotation.Roll = Lerp(ViewRotation.Roll, 0.0, 0.01);
        }
    
        //Pitch
        if (PlayerInput.aForward > 0 || PlayerInput.aLookUp < 0)
        {ViewRotation.Pitch -= 100;}
    
        if (PlayerInput.aForward < 0 || PlayerInput.aLookUp > 0)
        {ViewRotation.Pitch += 100;}
    
        //level out pitch when no pitch input
        if (PlayerInput.aForward == 0 && PlayerInput.aLookUp == 0)
        {
        TempRotationP = RInterpTo(Rotation, WorldInfo.Rotation, DeltaTime, 1.0);
        ViewRotation.Pitch = TempRotationP.Pitch;
        }
    	SetRotation(ViewRotation);
    
    	if (Pawn != None)
    	{
    		Pawn.FaceRotation(ViewRotation, DeltaTime);
    		Pawn.SetDesiredRotation(ViewRotation);
    		Pawn.Mesh.SetRBRotation(ViewRotation);
    	}
    }
    Tegleg_PlanePawn.uc
    Code:
    class Tegleg_PlanePawn extends UTPawn;
    
    simulated function PostBeginPlay()
    {
    	Super.PostBeginPlay();
    
        StartFlying();
    
        if(Mesh.PhysicsAssetInstance != None)
    	{
    		// Now set up the physics based on what we are currently doing.
    		if(Physics != PHYS_Flying)
    		{
    			SetPhysics(PHYS_Flying);
    		}
    	}
    	SetThirdPersonCamera(True);
    }
    
    simulated function FaceRotation(rotator NewRotation, float DeltaTime)
    {
    		SetRotation(NewRotation);
    }
    
    simulated singular event Rotator GetBaseAimRotation()
    {
    
       Return Rotation;
    
    }
    
    function SetMovementPhysics()
    {
       if (Physics != PHYS_Flying)
    	{
    		SetPhysics(PHYS_Flying);
    	}
    }
    
    simulated function bool CalcCamera( float fDeltaTime, out vector out_CamLoc, out rotator out_CamRot, out float out_FOV )
    {
        local vector X, Y, Z;
    
        GetAxes(Rotation, X, Y, Z);
    
            //set the cam location and rotation
    	out_CamLoc = Location - 200 * X;
    	out_CamRot = Rotation;
    
    	return true;
    }
    
    defaultproperties
    {
    	// Flags
    	bCanBeDamaged=true
    	bCanCrouch=false
    	bCanFly=true
    	bCanJump=false
    	bCanSwim=false
    	bCanTeleport=true
    	bCanWalk=false
    	bJumpCapable=false
    	bProjTarget=true
    	bSimulateGravity=false
    	bShouldBaseAtStartup=true
    
    	GroundSpeed=5000
    	AirSpeed=6000
    
    }
    heres a gametype that uses this pawn and controller
    TeglegGame_Plane.uc
    Code:
    class TeglegGame_Plane extends UTGame;
    
    static event class<GameInfo> SetGameType(string MapName, string Options, string Portal)
    {
    	return default.class;
    }
    
    defaultproperties
    {
    	PlayerControllerClass=class'Tegleg_PlaneController  '
    	DefaultPawnClass=class'Tegleg_PlanePawn'
    }
    Have Fun!

    there will be no updates or fixes, thats up to you.
    feel free to ask questions if theres something you dont understand.

    #2
    awesome, is good for a game where the player has the power to fly !!!! very good tuto tegleg !!!!

    Comment


      #3
      You should have gotten more replies here, i guess you didn't because no one really checks the documentation section
      btw it's a nice thing you got here, thanks for posting it,

      Comment


        #4
        AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.

        why didn't i see this before.

        Comment


          #5
          Nice one brah and thanks for sharing!

          Comment


            #6
            where would i put this code? im new at udk

            Comment


              #7
              http://forums.epicgames.com/threads/...8easy-guide%29
              http://udn.epicgames.com/Three/Devel...ptProject.html

              Comment

              Working...
              X