Results 1 to 40 of 40
  1. #1
    MSgt. Shooter Person
    Join Date
    Mar 2011
    Location
    Brisbane Australia
    Posts
    304

    Lightbulb How to put togeather a good sprint mechanic.

    Howdy people,

    I spent a little bit of time today putting togeather a tutorial on building a sprint mechanic. This is my first tutorial and as such its pretty rough. So I would appreciate any feedback etc..

    here is the link

    It goes through the process of setting up a sprint system with the following features:
    • A stamina system that allows the player to become puffed out and need to stop to catch his breath.
    • A basic HUD to show your stamina bar (as well as health).
    • Motionblur that blends on while sprinting then off again afterwards.
    • An interpolated thirdperson camera translation for moving into a different position for sprinting.
    • A system for interpolating the FOV of the player camera while sprinting.
    • Strafing and walking backwards are disabled while sprinting.
    • The speed that you can look around is reduced while sprinting.

    I would prefer if you left comments here, rather than on the blog.

    -Mega

    -Edit: heres a video of the system in action
    Last edited by meganaut; 03-30-2012 at 09:02 PM.

  2. #2

    Default

    Looks nice, probably going to use this in sprinting-state.

  3. #3
    MSgt. Shooter Person
    Join Date
    Jun 2011
    Posts
    186

    Default

    Thank your for this, I like the extra features such as the HUD and disabling walking backwards. Nice Job!

  4. #4
    The Sacrifice
    Join Date
    Jan 2012
    Posts
    76

    Default

    Nice tutorial. Have to say though, your website is very narrow!

  5. #5
    MSgt. Shooter Person
    Join Date
    Mar 2011
    Location
    Brisbane Australia
    Posts
    304

    Default

    Quote Originally Posted by Zaiteria View Post
    Nice tutorial. Have to say though, your website is very narrow!
    How dare you!!

    haha

  6. #6
    Iron Guard
    Join Date
    Jan 2012
    Location
    Denmark
    Posts
    547

    Default

    A YouTube of it in action would be nice to have, so you know what you get from this

  7. #7
    MSgt. Shooter Person
    Join Date
    Mar 2011
    Location
    Brisbane Australia
    Posts
    304

    Default

    Quote Originally Posted by vipar View Post
    A YouTube of it in action would be nice to have, so you know what you get from this
    A good idea. Ill put one togeather and update this post and the tutorial

  8. #8
    MSgt. Shooter Person
    Join Date
    Mar 2011
    Location
    Brisbane Australia
    Posts
    304

    Default

    Added a video

  9. #9
    MSgt. Shooter Person
    Join Date
    Feb 2012
    Posts
    265

    Default

    Great tutorial, have been trying to figure out how to stop sprinting backwards!

    Also, out of curiosity, do you extend from the UT classes or UDK?
    Last edited by Derp; 03-30-2012 at 10:02 PM.

  10. #10
    MSgt. Shooter Person
    Join Date
    Dec 2011
    Posts
    53

    Default

    Wow awesome this looks great!

    Plugging it in just getting the sprint and stamina functions in. no HUD or FX yet. When I plugged it in, I lost control over my character and camera. For a bit i had it working in myPawn.uc but then realized you said to put it in player controller... when it was in pawn it worked except for i never ran out of stamina :/

    Thanks again for the tut though! did i miss something?

    *myPlayerController.uc
    Code:
    class RunPlayerController extends PlayerController
        config(RunGame);
    
    // members for the custom mesh
    var SkeletalMesh defaultMesh;
    var MaterialInterface defaultMaterial0;
    var MaterialInterface defaultMaterial1;
    var AnimTree defaultAnimTree;
    var array <animset> defaultAnimSet;
    var AnimNodeSequence defaultAnimSeq;
    var PhysicsAsset defaultPhysicsAsset;
    //Sprint handling variables
    var float SprintSpeed;
    var float WalkSpeed;
    var float Stamina;
    
    var bool bSprinting;
    var bool bPuffedOut;
    
    //Update player rotation when walking
    state PlayerWalking
    {
    ignores SeePlayer, HearNoise, Bump;
    
    
      function ProcessMove(float DeltaTime, vector NewAccel, eDoubleClickDir DoubleClickMove, rotator DeltaRot)
        {
            local Rotator CameraRotationYawOnly;
            if( Pawn == None )
            {
                return;
            }
    
            if (Role == ROLE_Authority)
            {
                // Update ViewPitch for remote clients
                Pawn.SetRemoteViewPitch( Rotation.Pitch );
            }
    
            Pawn.Acceleration = NewAccel;
    
                 //get the controller yaw to transform our movement-accelerations by
        CameraRotationYawOnly.Yaw = Rotation.Yaw; 
        NewAccel = NewAccel>>CameraRotationYawOnly; //transform the input by the camera World orientation so that it's in World frame
        Pawn.Acceleration = NewAccel;
       
        Pawn.FaceRotation(Rotation,DeltaTime); //notify pawn of rotation
    
            CheckJumpOrDuck();
        }
    
        function PlayerMove( float DeltaTime )
        {
            local vector            X,Y,Z, NewAccel;
            local eDoubleClickDir    DoubleClickMove;
            local rotator            OldRotation;
            local bool                bSaveJump;
    
            if( Pawn == None )
            {
                GotoState('Dead');
            }
            else
            {
                GetAxes(Pawn.Rotation,X,Y,Z);
    
                // Update acceleration.
                NewAccel.X = PlayerInput.aForward;
                NewAccel.Y = PlayerInput.aStrafe;
                NewAccel.Z    = 0;
                //NewAccel = Pawn.AccelRate * Normal(NewAccel);
    
                if (IsLocalPlayerController())
                {
                    AdjustPlayerWalkingMoveAccel(NewAccel);
                }
    
                DoubleClickMove = PlayerInput.CheckForDoubleClickMove( DeltaTime/WorldInfo.TimeDilation );
    
                // Update rotation.
                OldRotation = Rotation;
                UpdateRotation( DeltaTime );
                bDoubleJump = false;
    
                if( bPressedJump && Pawn.CannotJumpNow() )
                {
                    bSaveJump = true;
                    bPressedJump = false;
                }
                else
                {
                    bSaveJump = false;
                }
    
                if( Role < ROLE_Authority ) // then save this move and replicate it
                {
                    ReplicateMove(DeltaTime, NewAccel, DoubleClickMove, OldRotation - Rotation);
                }
                else
                {
                    ProcessMove(DeltaTime, NewAccel, DoubleClickMove, OldRotation - Rotation);
                }
                bPressedJump = bSaveJump;
            }
        }
    
        event BeginState(Name PreviousStateName)
        {
            DoubleClickDir = DCLICK_None;
            bPressedJump = false;
            GroundPitch = 0;
            if ( Pawn != None )
            {
                Pawn.ShouldCrouch(false);
                if (Pawn.Physics != PHYS_Falling && Pawn.Physics != PHYS_RigidBody) // FIXME HACK!!!
                    Pawn.SetPhysics(Pawn.WalkingPhysics);
            }
        }
    
        event EndState(Name NextStateName)
        {
            GroundPitch = 0;
            if ( Pawn != None )
            {
                Pawn.SetRemoteViewPitch( 0 );
                if ( bDuck == 0 )
                {
                    Pawn.ShouldCrouch(false);
                }
            }
        }
    
    Begin:
    }
    
    //Controller rotates with turning input
    function UpdateRotation( float DeltaTime )
    {
    local Rotator   DeltaRot, newRotation, ViewRotation;
    
       ViewRotation = Rotation;
       if (Pawn!=none)
       {
          Pawn.SetDesiredRotation(ViewRotation);
       }
    
       // Calculate Delta to be applied on ViewRotation
       DeltaRot.Yaw   = PlayerInput.aTurn;
       DeltaRot.Pitch   = PlayerInput.aLookUp;
    
       ProcessViewRotation( DeltaTime, ViewRotation, DeltaRot );
       SetRotation(ViewRotation);
    
       NewRotation = ViewRotation;
       NewRotation.Roll = Rotation.Roll;
    
       if ( Pawn != None )
          Pawn.FaceRotation(NewRotation, deltatime); //notify pawn of rotation
    }   
    
    
    
    
    function startSprint()
    {
    ConsoleCommand("Sprint");
    
      if( !bPuffedOut )
      {
        Pawn.GroundSpeed = SprintSpeed;
     
        bSprinting = true;
      }
    }
     
    function stopSprint()
    {
      Pawn.GroundSpeed = WalkSpeed;
      bSprinting = false;
    
      //bPuffedOut = false; --only use this if you dont have a puffed timer func or a puffed state.
    }
    
    simulated function PlayerTick( float DeltaTime )
    {
     
       //sprinting use and replenish code.
      if( bSprinting && !bPuffedOut )
      {
        Stamina -= 20.4 * DeltaTime;
      }
      else
      {
        if( Stamina < 100 && !bPuffedOut )
        {
          Stamina += 0.2 * DeltaTime;
        }
      }
     
       //cases for low stamina
      if( Stamina <= 0 && !bPuffedOut )
      {
        //go into puffed state -- you could set up the state to play different idle and walking animations where the player looks workn out.
        //Also you could make the player stand still for a certain amount of time while they catch their breath.
        // i.e.  GoToState( 'Puffed', 'CatchBreath' );
        Stamina = 0;
        bPuffedOut = true;
       Pawn.GroundSpeed = 50;
        SetTimer( 3.f, false, 'CaughtBreath' );
      }
      else
      {
        if( !bSprinting && !bPuffedOut )
        {
          Pawn.GroundSpeed = WalkSpeed;
        }
      }
    
    }
     
    function CaughtBreath()
    {
      bPuffedOut = false;
    }
    
    
    // Sets the Pawns Mesh to the resources speced in the DefaultProperties
    public function resetMesh(){
    self.Pawn.Mesh.SetSkeletalMesh(defaultMesh);
    self.Pawn.Mesh.SetMaterial(0,defaultMaterial0);
    self.Pawn.Mesh.SetMaterial(1,defaultMaterial1);
    self.Pawn.Mesh.SetPhysicsAsset(defaultPhysicsAsset );
    self.Pawn.Mesh.AnimSets=defaultAnimSet;
    self.Pawn.Mesh.SetAnimTreeTemplate(defaultAnimTree );
    }
    
    
    DefaultProperties
    {
    
    
    InputClass=class'Run.RunPlayerInput'
    CameraClass=class'Run.RunPlayerCamera'
    defaultMesh=SkeletalMesh'Run_Core.Character.Run_Girl_skel'
    defaultAnimTree=AnimTree'Run_Core.Character.Character_movement'
    defaultAnimSet(0)=AnimSet'Run_Core.Character.Run_Girl_skel_Anims'
    defaultPhysicsAsset=PhysicsAsset'Run_Core.Character.Run_Girl_skel_Physics'
    //UTHUDBase(myHUD).bCrosshairShow = false
    
    
        WalkSpeed=350.0
        SprintSpeed=900.0
        bSprinting=false
        bPuffedOut = false
        Stamina=100.0
    
    }

  11. #11
    MSgt. Shooter Person
    Join Date
    Jun 2011
    Posts
    186

    Default

    Has anyone had any luck getting getting this set up with classes extending from UDKBase?

  12. #12
    MSgt. Shooter Person
    Join Date
    Mar 2011
    Location
    Brisbane Australia
    Posts
    304

    Default

    Quote Originally Posted by Derp View Post
    Great tutorial, have been trying to figure out how to stop sprinting backwards!

    Also, out of curiosity, do you extend from the UT classes or UDK?
    All my classes are extended from UDK. no UT code (except that which i stole from UT classes) is used

  13. #13
    MSgt. Shooter Person
    Join Date
    Mar 2011
    Location
    Brisbane Australia
    Posts
    304

    Default

    Quote Originally Posted by Whaaabamb View Post
    Wow awesome this looks great!

    Plugging it in just getting the sprint and stamina functions in. no HUD or FX yet. When I plugged it in, I lost control over my character and camera. For a bit i had it working in myPawn.uc but then realized you said to put it in player controller... when it was in pawn it worked except for i never ran out of stamina :/
    I'm not certain... It may be because i extended my custom controllre class from UDKPlayerController. give that a try and let me know.

    -Mega

  14. #14
    Iron Guard
    Join Date
    Jan 2012
    Location
    Denmark
    Posts
    547

    Default

    I wanted to do a little extra with your sprinting, and I just can't really make it work.
    I haven't implemented much of the system yet, but usually I like to compile from time to time, so that I know what I've done so far works...habit from making Java :P

    So any way.
    What I am trying to do, is make the HUD show a message in the middle of the screen, if the player tries to sprint, but can't, as I don't want the Sprint Meter you show in the video ^^
    So I thought "Why not do it like Java since this is Java/C++ inspired?" So I tried to make the function static, and then did HS_GameHUD.DisplayExhausted(...); in my player controller but apparently that is not how to do it...some help would be nice

    This is from my Player Controller, which extends UTPlayerController:
    Code:
    function startSprint() {
    	if(!bExhausted) {
    		Pawn.GroundSpeed = SprintSpeed;
    		bSprinting = true;
    	} else {
    		HS_GameHUD.DisplayExhausted("You are too Exhausted to Sprint.");
    	}
    }
    And this is from my HUD class which extends UTHud:

    Code:
    function DisplayExhausted(string s) {
    	Canvas.SetPos((Canvas.ClipX / 2), (Canvas.ClipY /2));
    	Canvas.DrawText(s, true, 2.0f, 2.0f);
    }

  15. #15
    MSgt. Shooter Person
    Join Date
    Mar 2011
    Location
    Brisbane Australia
    Posts
    304

    Default

    Well you dont need the function to be static since you only use one HUD. The static keyword should be used to make a variable (or function i guess) exist in one instance accross all seperate instances of that class. I'm pretty sure thats how it works in java too, so I'm not really understanding your reasoning behind making the function static.

    The other thing is you should set a draw colour for your text:
    Code:
     Canvas.DrawColor = WhiteColor;
    That should work if you are using a version of my HUD

    -Mega

  16. #16
    Iron Guard
    Join Date
    Jan 2012
    Location
    Denmark
    Posts
    547

    Default

    Sooo, I tried to take what you had, and turn it into states...
    This is what I got so far. I am a newb at UnrealScript, so bare with me, if this burn your eyes out or something

    From my PlayerController
    Code:
    auto state PlayerIdle{
    	simulated function PlayerTick(float DeltaTime) {
    		if(VSize(Pawn.Velocity) > 0 && !bExhausted) {
    			GotoState('PlayerRunning');
    		} else {
    			GotoState('PlayerWalking');
    		}
    
    		if(VSize(Pawn.Velocity) == 0) {
    			if(Stamina < 100.0) {
    				Stamina += 0.2;
    				if(Stamina > 10.0) {
    					bExhausted = false;
    				}
    			} else if(Stamina > 100.0) {
    				Stamina = 100.0;
    			}
    		}
    	}
    }
    
    state PlayerSprinting {
    	simulated function PlayerTick(float DeltaTime) {
    		bSprinting = true;
    		Pawn.GroundSpeed = SprintSpeed;
    		if(Stamina == 0) {
    			bSprinting = false;
    			GotoState('PlayerExhausted');
    		} else {
    			Stamina -= 0.8;
    		}
    		//TODO: Put Code to trigger PlayerRunning State.
    		/**
    		 * Pseudo Code
    		 * if(LeftShift is not Pressed)
    		 *      GotoState('PlayerRunning');
    		 * */
    
    	}
    }
    
    state PlayerRunning {
    	simulated function PlayerTick(float DeltaTime) {
    		if(VSize(Pawn.Velocity) == 0) {
    			Gotostate('PlayerIdle');
    		}
    
    		//TODO: Put Code to trigger PlayerSprinting State.
    		/**
    		 * Pseudo Code
    		 * if(LeftShift is Pressed && Stamina is Greater than 10)
    		 *      GotoState('PlayerSprinting');
    		 * */
    
    		if(Stamina < 100) {
    			Stamina += 0.2;
    		} else if(Stamina > 100) {
    			Stamina = 100.0;
    		}
    	}
    }
    
    state PlayerWalking {
    	simulated function PlayerTick(float DeltaTime) {
    		Pawn.GroundSpeed = WalkSpeed;
    		// Stamina is now above the limit, so we allow the player to Run again
    		if(VSize(Pawn.Velocity) == 0) {
    			GotoState('PlayerIdle');
    		}
    
    		if(Stamina > 10) {
    			bExhausted = false;
    			GotoState('PlayerRunning');
    		} else {
    			Stamina += 0.2;
    		}
    	}
    }
    
    state PlayerExhausted {
    	// Exhaustion should stay for 5 Seconds before jumping
    	// to the PlayerWalking State
    	simulated function PlayerTick(float DeltaTime) {
    		Pawn.GroundSpeed = 0.0;
    		bExhausted = true;
    		SetTimer(5.f, false, 'PlayerWalking');
    	}
    }
    
    defaultproperties
    {
    	Stamina = 100.0
    	SprintSpeed = 650.0
    	WalkSpeed = 350
    	defaultSpeed = 400.0
    	bSprinting = false
    	bExhausted = false
    }
    Last edited by vipar; 03-31-2012 at 10:25 AM.

  17. #17
    MSgt. Shooter Person
    Join Date
    Mar 2011
    Location
    Brisbane Australia
    Posts
    304

    Default

    Imho, It would be best to leave the stamina regen code in the global playertick function. And in your startsprint function, go to the sprinting state. then in the stopsprint function, go back to walking (only if the player isnt exhausted). I can see what you are trying to do there, but I would be using states more to control animationblendlists or to play individual animations, aswell as change control over the player (like slowing the camera rotation rate, and disabling strafing)

    But if you are comfortable doing it like you are, then by all means continue As far as I know there is no "right way" only a bunch of alternative ways.

    -Mega

  18. #18
    Iron Guard
    Join Date
    Jan 2012
    Location
    Denmark
    Posts
    547

    Default

    I typically see the "right way" as the most efficient and least memory consuming..
    Javaaaaaa.... <_<


    But how about we try and work your great system, into something that is state controlled instead? I think it would benefit a lot more! :3

  19. #19
    Iron Guard
    Join Date
    Jan 2012
    Location
    Denmark
    Posts
    547

    Default

    Not like, entirely state controlled like what I tried but, you know.


    EDIT:
    Something like this?
    It's probably not entirely like this, because when I spawn I can't move in any direction with the keys, or with the mouse...
    Also, it kept saying that DeltaRot in your UpdateRotation() function was a bad command or expression.
    ZoomSpeed is never defined anywhere, unless you want us to define it ourselves, so it gives the same error.

    Code:
    class HS_PlayerController extends UTPlayerController;
    
    var float SprintSpeed, WalkSpeed, defaultSpeed, ZoomSpeed, Stamina;
    var bool bSprinting, bExhausted, bWalking;
    var PostProcessSettings blurSettings;
    
    // Regeneration Rate and Degeneration Rate for Stamina.
    var float regenRate, degenRate;
    
    simulated event PostBeginPlay() {
    	// Setting up Camera Blur
    	blurSettings.bEnableMotionBlur = true;
    	blurSettings.bOverride_EnableMotionBlur = true;
    	blurSettings.bOverride_MotionBlur_Amount =  true;
    	blurSettings.MotionBlur_Amount = 50.f;
    	super.PostBeginPlay();
    }
    
    simulated function PlayerTick(float DeltaTime) {
    
    	/** STAMINA REGEN/DEGENERATION CODE **/
    
    	if(bSprinting && !bExhausted && VSize(Pawn.Velocity) > 20) {
    		Stamina -= degenRate;
    		// Is Stamina below Max, and is the player not exhausted or sprinting?
    	} else if(Stamina < 100.0 && !bExhausted && !bSprinting) {
    		// Regenerate some Stamina
    		Stamina += regenRate;
    	}
    
    	if(Stamina <= 0 && !bExhausted) {
    		Stamina = 0;
    		bExhausted = true;
    		Pawn.GroundSpeed = 0.0;
    		GotoState('Exhausted');
    	}
    
    	if(Stamina >= 10 && bWalking) {
    		GotoState('Running');
    	}
    
    	//TODO: Put Code to trigger PlayerSprinting State.
    		/**
    		 * Pseudo Code
    		 * if(LeftShift is Pressed and the player is not Exhausted)
    		 *      GotoState('PlayerSprinting');
    		 * */
    
    	// If Stamina somehow became more than 100, then we just set it back to 100
    	if(Stamina > 100.0) {
    		Stamina = 100.0;
    	}
    }
    
    function CatchBreath() {
    	Stamina = 10.0;
    	GotoState('Walking');
    }
    
    state PlayerSprinting extends PlayerWalking {
    
            // Says it doesn't know what DeltaRot is
    	//function UpdateRotation(float DeltaTime) {
    	//	if(bSprinting) {
    	//		DeltaRot.Yaw = PlayerInpit.aTurn / 5;
    	//		DeltaRot.Pitch = PlayerInput.aLookIp / 2;
    	//	} else {
    	//		DeltaRot.Yaw  = PlayerInput.aTurn;
    	//		DeltaRot.Pitch  = PlayerInput.aLookUp;
    	//	}
    	//}
    
    	function PlayerMove(float DeltaTime) {
    		local vector X, Y, Z, NewAccel;
    		local eDoubleClickDir DoubleClickMove;
    		local rotator OldRotation;
    		local bool bSaveJump;
    
    		if(Pawn == none) {
    			Gotostate('Dead');
    		} else {
    			GetAxes(Pawn.Rotation,X,Y,Z);
     
    			// Update acceleration.
     
    			if( bSprinting ) {
    				if( PlayerInput.aForward > 0 ) { //if the player is moving forward
    					NewAccel = PlayerInput.aForward*X + 0*Y; //cancel all strafing
    				} else { 
    					NewAccel = 0*X + 0*Y; //otherwise disable all movement ( if walking backward )
    				}
    			} else { 
    				NewAccel = PlayerInput.aForward*X + PlayerInput.aStrafe*Y; //if not sprinting perform normally.
    			}
    			NewAccel.Z  = 0;
    			NewAccel = Pawn.AccelRate * Normal(NewAccel);
    			
    			if (IsLocalPlayerController()) {
    				AdjustPlayerWalkingMoveAccel(NewAccel);
    			}
    			DoubleClickMove = PlayerInput.CheckForDoubleClickMove( DeltaTime/WorldInfo.TimeDilation );
    			// Update rotation.
    			OldRotation = Rotation;
    			UpdateRotation( DeltaTime );
    			bDoubleJump = false;
    			
    			if( bPressedJump && Pawn.CannotJumpNow()) {
    				bSaveJump = true;
    				bPressedJump = false;
    			} else {
    				bSaveJump = false;
    			}
    			
    			if( Role < ROLE_Authority ) { // then save this move and replicate it
    				ReplicateMove(DeltaTime, NewAccel, DoubleClickMove, OldRotation - Rotation);
    			} else {
    				ProcessMove(DeltaTime, NewAccel, DoubleClickMove, OldRotation - Rotation);
    			}
    			bPressedJump = bSaveJump;
    		}
    	}
    	
    	function SprintCamera() {
    		local vector deltaCamOffset;
    		local float deltaCamOffsetRate;
    
    		// FOV Zooming
    		if((bSprinting && !bExhausted && PlayerCamera.DefaultFOV < 120 && VSize(Pawn.Velocity) > 20 )) {
    			PlayerCamera.DefaultFOV += 3;
    		} else if((!bSprinting || bExhausted) && PlayerCamera.DefaultFOV > PlayerCamera.default.DefaultFOV)  {
    			PlayerCamera.DefaultFOV -= 3;
    		}
    
    		// Cam Offset Zooming
    		deltaCamOffset = HS_Camera(PlayerCamera).default.CamOffset;
    		deltaCamOffsetRate = (PlayerCamera.DefaultFOV - PlayerCamera.default.DefaultFOV);
    		if(deltaCamOffsetRate != 0) {
    			deltaCamOffsetRate = deltaCamOffsetRate / 60;
    			deltaCamOffset.X += (HS_Camera(PlayerCamera).SprintOffset.X - HS_Camera(PlayerCamera).default.CamOffset.X) * deltaCamOffsetRate;
    			deltaCamOffset.Y += (HS_Camera(PlayerCamera).SprintOffset.Y - HS_Camera(PlayerCamera).default.CamOffset.Y) * deltaCamOffsetRate;
    			deltaCamOffset.Z += (HS_Camera(PlayerCamera).SprintOffset.Z - HS_Camera(PlayerCamera).default.CamOffset.Z) * deltaCamOffsetRate;
    			HS_Camera(PlayerCamera).CamOffset = deltaCamOffset;
    		} else {
    			HS_Camera(PlayerCamera).CamOffset = HS_Camera(PlayerCamera).default.CamOffset;
    		}
    	}
    
    Begin:
    	bSprinting = true;
    	// Motion Blur Fading
    	while(bSprinting) {
    		if((VSize(Pawn.Velocity) > 20) || (VSize(Pawn.Velocity) > ZoomSpeed && PlayerCamera.CamOverridePostProcessAlpha < 1.f)) {
    			LocalPlayer(Player).OverridePostProcessSettings(blurSettings, 0.5f);
    			SprintCamera();
    		}
    	}
    	LocalPlayer(Player).ClearPostProcessSettingsOverride(0.5f);
    }
    
    state Running {
    Begin:
    	Pawn.GroundSpeed = defaultSpeed;
    	bWalking = false;
    }
    
    state Walking {
    Begin:
    	Pawn.GroundSpeed = WalkSpeed;
    	bExhausted = false;
    	bWalking = true;
    }
    
    state Exhausted {
    Begin:
    	// A Player is exhausted for 5 seconds, while catching his breath
    	SetTimer(5.f, false, 'CatchBreath');
    }
    
    defaultproperties
    {
    	Stamina = 100.0
    	regenRate = 0.2
    	degenRate = 0.8
    	SprintSpeed = 650.0
    	WalkSpeed = 350.0
    	defaultSpeed = 400.0
    	ZoomSpeed = 10.0
    	bSprinting = false
    	bExhausted = false
    	bWalking = false
    }
    Last edited by vipar; 03-31-2012 at 02:19 PM.

  20. #20
    MSgt. Shooter Person
    Join Date
    Mar 2011
    Location
    Brisbane Australia
    Posts
    304

    Default

    hmmm, i may have missed out the definition of deltarot, in which case yes you need to define it ( its a rotator ).
    Also, zoomspeed should be set only slightly lower than your sprint speed, Zoomspeed will just trigger the motion blur effect if you are falling faster than the zoomspeed.

    Somone else has already commented that overriding the PlayerMove function destroyed their player movement. I belive its to do with you extending from UTPlayerController. All my code is based off extending from UDKPlayerController. Try changing the extends and see what happens.

    -Mega

  21. #21
    Iron Guard
    Join Date
    Jan 2012
    Location
    Denmark
    Posts
    547

    Default

    It keeps telling me, that = is a bad expression for DeltaRot.
    Error, Bad or missing expression in '='

    I've declared DeltaRot like
    var rotator DeltaRot;

    And didn't give it any value in the default properties.

    Code:
    function UpdateRotation(float DeltaTime) {
    		if(bSprinting) {
    			DeltaRot.Yaw = PlayerInpit.aTurn / 5;
    			DeltaRot.Pitch = PlayerInput.aLookIp / 2;
    		} else {
    			DeltaRot.Yaw  = PlayerInput.aTurn;
    			DeltaRot.Pitch  = PlayerInput.aLookUp;
    		}
    	}

  22. #22
    MSgt. Shooter Person
    Join Date
    Mar 2011
    Location
    Brisbane Australia
    Posts
    304

    Default

    Ohh, lol. ok deltarot is decalred in UTPlayerController, and like i said i ripped some code from there. Ill post my entire updaterotation function but BEWARE: If you have a standard third person camera, this will mess with it.

    Code:
    function UpdateRotation( float DeltaTime )
    {
      local Rotator DeltaRot, ViewRotation;
      local float rotationDif, rotdif;
    
      ViewRotation = Rotation;
    
      if (Pawn!=none)
      {
        Pawn.SetDesiredRotation(ViewRotation);
      }
    
      // Calculate Delta to be applied on ViewRotation
      if( bSprinting )
      {
        DeltaRot.Yaw  = PlayerInput.aTurn / 5;
        DeltaRot.Pitch  = PlayerInput.aLookUp / 2;
      }
      else
      {
        DeltaRot.Yaw  = PlayerInput.aTurn;
        DeltaRot.Pitch  = PlayerInput.aLookUp;
      }
    
      ProcessViewRotation( DeltaTime, ViewRotation, DeltaRot );
      SetRotation(ViewRotation);
    
      ViewShake( deltaTime );
    
      DeltaRot = pawn.Rotation;
      DeltaRot.Roll = Rotation.Roll;
      DeltaRot.Pitch = 0;
      DeltaRot.Roll = 0;
    
      ViewRotation.Pitch = 0;
      ViewRotation.Roll = 0;
    
      if( bUsingObject && Iobj != none )
      {
        if( IObj.bRotationLocked || IObj.bLinearLocked )
        {
          viewRotation = rotator( IObj.Location - Pawn.Location );
          DeltaRot.Yaw = viewRotation.Yaw;
          Pawn.FaceRotation( DeltaRot, 1.f );
          return;
        }
      }
    
      if ( Pawn != None )
      {
        rotdif = ViewRotation.Yaw - DeltaRot.Yaw;
        rotationDif = RDiff( ViewRotation , DeltaRot );
        //`log( rotationDif );
    
        // smooth rotation of player when moving
        if( rotdif > 0 && VSize(Pawn.Velocity) > 0 )
        {
          if( rotationDif < 10 )
          {
            if( !bSprinting && pawn.Physics != PHYS_Falling)
            {
              Pawn.GroundSpeed = pawn.default.GroundSpeed;
            }
            DeltaRot.Yaw = ViewRotation.Yaw;
          }
          else
          {
            if( !bSprinting && pawn.Physics != PHYS_Falling)
            {
              Pawn.GroundSpeed = 10;
            }
    
            DeltaRot.Yaw += 2000;
          }
        }
        else if( rotdif < 0 && VSize(Pawn.Velocity) > 0 )
        {
          if( rotationDif < 10 )
          {
            if( !bSprinting && pawn.Physics != PHYS_Falling )
            {
              Pawn.GroundSpeed = pawn.default.GroundSpeed;
            }
            DeltaRot.Yaw = ViewRotation.Yaw;
          }
          else
          {
            if( !bSprinting && pawn.Physics != PHYS_Falling)
            {
              Pawn.GroundSpeed = 10;
            }
            DeltaRot.Yaw -= 2000;
          }
        }
        Pawn.FaceRotation( DeltaRot, 1.f );
      }
    }

  23. #23
    Iron Guard
    Join Date
    Jan 2012
    Location
    Denmark
    Posts
    547

    Default

    Both bUsingObject and IObj doesn't seem to be declared anywhere...but are used

    Code:
    if(bUsingObject && Iobj != none) {
    			if(IObj.bRotationLocked || IObj.bLinearLocked) {
    				viewRotation = rotator(IObj.Location - Pawn.Location);
    				DeltaRot.Yaw = viewRotation.Yaw;
    				Pawn.FaceRotation(DeltaRot, 1.f);
    				return;
    			}
    		}

  24. #24
    MSgt. Shooter Person
    Join Date
    Dec 2011
    Posts
    53

    Default

    So I changed to UDKPlayerController and nothing changed

    In case I had messed something up I started over. Checking my build after each step.
    It wasn't until I added this that it broke my camera and movement.

    Code:
    simulated function PlayerTick( float DeltaTime )
    {
      ...
       //sprinting use and replenish code.
      if( bSprinting && !bPuffedOut && VSize(Pawn.Velocity) > 20 )
      {
        Stamina -= 0.4;
      }
      else
      {
        if( Stamina < 100 && !bPuffedOut )
        {
          Stamina += 0.2;
        }
      }
     
       //cases for low stamina
      if( Stamina <= 0 && !bPuffedOut )
      {
        //go into puffed state -- you could set up the state to play different idle and walking animations where the player looks workn out.
        //Also you could make the player stand still for a certain amount of time while they catch their breath.
        // i.e.  GoToState( 'Puffed', 'CatchBreath' );
        Stamina = 0;
        bPuffedOut = true;
        Pawn.GroundSpeed = 0;
        SetTimer( 3.f, false, 'CaughtBreath' );
      }
      else if( Stamina < 50 )
      {
        if( !bSprinting && !bPuffedOut )
        {
          Pawn.GroundSpeed = WalkSpeed / 2;
        }
      }
      else
      {
        if( !bSprinting && !bPuffedOut )
        {
          Pawn.GroundSpeed = WalkSpeed;
        }
      }
    ...
    }
     
    function CaughtBreath()
    {
      bPuffedOut = false;
    }


    This is the other part of my player controller... I admit to being baffled by what would be breaking this.

    Code:
    //Controller rotates with turning input
    function UpdateRotation( float DeltaTime )
    {
    local Rotator   DeltaRot, newRotation, ViewRotation;
    
       ViewRotation = Rotation;
       if (Pawn!=none)
       {
          Pawn.SetDesiredRotation(ViewRotation);
       }
    
       // Calculate Delta to be applied on ViewRotation
       DeltaRot.Yaw   = PlayerInput.aTurn;
       DeltaRot.Pitch   = PlayerInput.aLookUp;
    
       ProcessViewRotation( DeltaTime, ViewRotation, DeltaRot );
       SetRotation(ViewRotation);
    
       NewRotation = ViewRotation;
       NewRotation.Roll = Rotation.Roll;
    
       if ( Pawn != None )
          Pawn.FaceRotation(NewRotation, deltatime); //notify pawn of rotation
    }   
    //Update player rotation when walking
    state PlayerWalking
    {
    ignores SeePlayer, HearNoise, Bump;
    
    
      function ProcessMove(float DeltaTime, vector NewAccel, eDoubleClickDir DoubleClickMove, rotator DeltaRot)
    	{
    		local Rotator CameraRotationYawOnly;
    		if( Pawn == None )
    		{
    			return;
    		}
    
    		if (Role == ROLE_Authority)
    		{
    			// Update ViewPitch for remote clients
    			Pawn.SetRemoteViewPitch( Rotation.Pitch );
    		}
    
    		Pawn.Acceleration = NewAccel;
    
    			 //get the controller yaw to transform our movement-accelerations by
    	CameraRotationYawOnly.Yaw = Rotation.Yaw; 
    	NewAccel = NewAccel>>CameraRotationYawOnly; //transform the input by the camera World orientation so that it's in World frame
    	Pawn.Acceleration = NewAccel;
       
    	Pawn.FaceRotation(Rotation,DeltaTime); //notify pawn of rotation
    
    		CheckJumpOrDuck();
    	}
    
    	function PlayerMove( float DeltaTime )
    	{
    		local vector			X,Y,Z, NewAccel;
    		local eDoubleClickDir	DoubleClickMove;
    		local rotator			OldRotation;
    		local bool				bSaveJump;
    
    		if( Pawn == None )
    		{
    			GotoState('Dead');
    		}
    		else
    		{
    			GetAxes(Pawn.Rotation,X,Y,Z);
    
    			// Update acceleration.
    			NewAccel.X = PlayerInput.aForward;
    			NewAccel.Y = PlayerInput.aStrafe;
    			NewAccel.Z	= 0;
    			//NewAccel = Pawn.AccelRate * Normal(NewAccel);
    
    			if (IsLocalPlayerController())
    			{
    				AdjustPlayerWalkingMoveAccel(NewAccel);
    			}
    
    			DoubleClickMove = PlayerInput.CheckForDoubleClickMove( DeltaTime/WorldInfo.TimeDilation );
    
    			// Update rotation.
    			OldRotation = Rotation;
    			UpdateRotation( DeltaTime );
    			bDoubleJump = false;
    
    			if( bPressedJump && Pawn.CannotJumpNow() )
    			{
    				bSaveJump = true;
    				bPressedJump = false;
    			}
    			else
    			{
    				bSaveJump = false;
    			}
    
    			if( Role < ROLE_Authority ) // then save this move and replicate it
    			{
    				ReplicateMove(DeltaTime, NewAccel, DoubleClickMove, OldRotation - Rotation);
    			}
    			else
    			{
    				ProcessMove(DeltaTime, NewAccel, DoubleClickMove, OldRotation - Rotation);
    			}
    			bPressedJump = bSaveJump;
    		}
    	}
    
    	event BeginState(Name PreviousStateName)
    	{
    		DoubleClickDir = DCLICK_None;
    		bPressedJump = false;
    		GroundPitch = 0;
    		if ( Pawn != None )
    		{
    			Pawn.ShouldCrouch(false);
    			if (Pawn.Physics != PHYS_Falling && Pawn.Physics != PHYS_RigidBody) // FIXME HACK!!!
    				Pawn.SetPhysics(Pawn.WalkingPhysics);
    		}
    	}
    
    	event EndState(Name NextStateName)
    	{
    		GroundPitch = 0;
    		if ( Pawn != None )
    		{
    			Pawn.SetRemoteViewPitch( 0 );
    			if ( bDuck == 0 )
    			{
    				Pawn.ShouldCrouch(false);
    			}
    		}
    	}
    
    Begin:
    }
    Last edited by Whaaabamb; 03-31-2012 at 08:34 PM.

  25. #25
    MSgt. Shooter Person
    Join Date
    Mar 2011
    Location
    Brisbane Australia
    Posts
    304

    Default

    Do you actually have those "..."s in your code?

  26. #26
    MSgt. Shooter Person
    Join Date
    Dec 2011
    Posts
    53

    Default

    hehe, no I took those out.

  27. #27
    MSgt. Shooter Person
    Join Date
    Dec 2011
    Posts
    53

    Default

    So i keep pealing away the code. even putting this in

    Code:
    simulated function PlayerTick( float DeltaTime )
    {
    }
    Breaks it.... It compiles but in game no camera/playermovement

    Edit* I changed playerTick to tick and it stopped breaking my controls/camera.!!!

    Now i just cant run out of stamina though:/
    Last edited by Whaaabamb; 03-31-2012 at 09:22 PM.

  28. #28
    MSgt. Shooter Person
    Join Date
    Mar 2011
    Location
    Brisbane Australia
    Posts
    304

    Default

    oh ok.. maybe try using playertick again, and adding teh line Super.PlayerTick( deltaTime ); at the end of teh player tick function

    -Mega

  29. #29
    MSgt. Shooter Person
    Join Date
    Dec 2011
    Posts
    53

    Default

    YOU ARE THE MAN!!!! Thank you this is so awesome! Great Tutorial and thanks for the help!

    So just for my knowledge what did that do?

  30. #30
    MSgt. Shooter Person
    Join Date
    Mar 2011
    Location
    Brisbane Australia
    Posts
    304

    Default

    calling super.PlayerTick calls the playertick function in the parent class ( its a fundamental Object-oriented programming technique ). If you hadnt declared playertick in your custom controller, then it would automatically use the playertick function in the parent class

    -Mega

  31. #31
    MSgt. Shooter Person
    Join Date
    Mar 2011
    Location
    Brisbane Australia
    Posts
    304

    Default

    ill make some updates to the tutorial

  32. #32
    MSgt. Shooter Person
    Join Date
    Dec 2011
    Posts
    53

    Default

    Thanks again for all the help!

    here is a clip of it in action

    http://www.youtube.com/watch?v=dQkKc...rebCmq7FWPXiI=

    only thing i don't have working is the camera zoom, my camera is set up a bit different than yours so its a bit confusing for my non coder mind.

  33. #33
    MSgt. Shooter Person
    Join Date
    Mar 2011
    Location
    Brisbane Australia
    Posts
    304

    Default

    Quote Originally Posted by Whaaabamb View Post
    looks good!

  34. #34
    MSgt. Shooter Person
    Join Date
    Nov 2009
    Posts
    391

    Default

    the sprint still works even in reverse AFAI in the Feb-2012 version. Maybe something changed or perhaps I missed/typo in the code.

    thanks for sharing though it gave me some ideas of my own on how to do some other things.

  35. #35
    MSgt. Shooter Person
    Join Date
    Mar 2011
    Location
    Brisbane Australia
    Posts
    304

    Default

    Quote Originally Posted by DJMidknight View Post
    the sprint still works even in reverse AFAI in the Feb-2012 version. Maybe something changed or perhaps I missed/typo in the code.

    thanks for sharing though it gave me some ideas of my own on how to do some other things.
    The running backward is disabled in the final section. In the playerMove function, you can see there is a check weather the playerInput.Aforward > 0 (i.e. moving forward). That disables all backward movement because aForward is in the negative when moving backward.

    Maybe you missed that part

  36. #36
    Redeemer
    Join Date
    Nov 2009
    Location
    Caracas
    Posts
    1,819
    Gamer IDs

    Gamertag: daimakupikoro PSN ID: lone_vampire

    Default

    really good tutorial, thanks
    http://vincenzoravo.vrs.com.ve http://www.slaughtermaze.com

    please don't fill my inbox with questions, ask in the forum, the answers will help you and others !!!

  37. #37

    Default

    Quote Originally Posted by daimaku View Post
    really good tutorial, thanks
    agreed this is very awesome. I tested out the functionality and got it compiled correctly but I'm having some issues binding it to the spacebar. I've looked up some tutorials but I think I'm missing something. With this exact script what lines would I have to add in the "DefaultInput.ini" file? ><

    Thanks in advance, also for the awesome sprint function

  38. #38
    MSgt. Shooter Person
    Join Date
    Mar 2011
    Location
    Brisbane Australia
    Posts
    304

    Default

    theres plenty of tutes on setting up new binds out there. make sure you change the StartSprint and StopSprint functions to exec functions


  39. #39
    MSgt. Shooter Person
    Join Date
    Jan 2012
    Posts
    37

    Default

    can anyone put the code please? Website off

  40. #40

    Default

    Has someone a code of this awesome thing? Or saved pages of site?


 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Copyright ©2009-2011 Epic Games, Inc. All Rights Reserved.
Digital Point modules: Sphinx-based search vBulletin skin by CompletevB.com.