No announcement yet.

Trouble creating a custom jump function

  • Filter
  • Time
  • Show
Clear All
new posts

    Trouble creating a custom jump function


    Relatively new to UnrealScript and the UDK environment, but I've been coding for a few years. I've been trying to create a custom jump function for a sidescroller I'm working on. I wasn't really impressed with the StarterPlatformKit's jump that came with it, I was looking for more of a Mario style jump where you go up as you hold the key and then come down after release. For simplicity's sake I'm just trying to get the character to go up when space is held and then to come back down after release, after that I'll implement a max height and a timer to stop the player after a certain time has passed. So far all I've managed to do is to have my key presses and releases recognized by the game via custom functions attached to the spacebar from DefaultInput.ini, but I have had absolutely no luck in getting a character to actually jump. I've googled and googled and had no luck in figuring out what you have to manipulate to get the character to actually rise.

    I'm attaching the TestPawn class that has the custom functions I've defined.

    Any push in the right direction would be greatly appreciated!

    class TestPawn extends UDNPawn
    	simulated function Tick(float DeltaTime)
    		local vector tmpLocation;
    			tmpLocation = Location;
    			tmpLocation.Y = 500;
    	exec function NewJump()
    	exec function Fall() 
    	function bool Dodge(eDoubleClickDir DoubleClickMove)
    		return false;

    After some extensive searching on this forum I found everything I needed to make my jump work, I just don't see a way to close out the thread :X


      In the default implementation, the PlayerInput class has an exec function called Jump which just flips the bPressedJump boolean. From here, in the PlayerWalking state the process move function calls CheckJumpOrDuck. In CheckJumpOrDuck, if bPressedJump is true and the pawn is valid the PlayerController tells the pawn to preform the jump by calling DoJump. DoJump just simply adds a certain amount to the velocities Z component and sets the physics to PHYS_Falling. So far pretty simple.

      If you kept this setup, your pawn should jump no problem.

      In order to get the functionality you want, you could create an exec function that is called when space bar is released. This exec function would set the Z component of the pawn's velocity to 0 and bPressedJump to false. If you follow the logic that epic used to start the jump while coding how the jump ends you should be able to make this work in a SP and MP environment.

      If you wanted different functionality, such as the player falling faster (at this point it SHOULD be only gravity) add a negative value to the z component of velocity of the pawn. Also, keep in mind that if you're using the default functionality for the jump eventually the pawn will come back down even if you don't let go of the space bar. If you don't want gravity to affect your pawn when it is jumping up set the physics of the pawn to PHYS_Flying and then set the physics of the pawn to PHYS_Falling when spacebar is released.