Download

Player movement along Z-axis

Hello!

I’m currently making a 3D side scroller and I’m trying to figure out how to set up my blueprint to make my player move up along the Z axis when I hold a button or press on the screen, and then the player will fall back to the ground with the physics. (kind of like JetPack JoyRide). I’ve searched the internet up and down for help but can’t seem to find anything. I’m still fairly new to blueprints but know more than the average beginner. Any tutorials or help would be appreciated!

Thanks!

Mike

Please forgive me if this sounds patronizing, but because I don’t know your level of expertise I’ll explain everything in great detail :slight_smile:

  1. This is a gate node, it stops execution (through “Enter”) until it’s opened, then stops execution again when it’s closed.
  2. This is event Tick, which is an event called every time the game draws another frame on screen. It has a Delta Seconds parameter that is equal to the number of seconds it took to draw said frame. The execution pin from this is routed into the Gate.
  3. This is an input node. It will fire an execution whenever the J key is pressed down or let go. Pressed goes to “Open” on the gate, Released goes to “Close.” When they J key is pressed, execution through the gate will be passed and when it’s released, execution will be blocked. You can use any key or input event for this that you want, I’m just using J as an example.
  4. This is a reference to your player pawn/character. This is the object that your player possesses and controls.
  5. Set Actor Location will manipulate the position of your player pawn. When the gate is open and execution is passed, it will change your pawn’s position.
  6. The position, or location, that we’re passing through is equal to its current X and current Y (so the only thing that will change is the Z) and the Z will be created through a short calculation. You can right-click on your Vector pin and choose “Split Struct Pin” to manipulate individual axes of the Vector.

What we feed into Z is Delta Seconds * Z Up Rate(9), which is a float variable I made to modulate the speed at which the pawn flies up. Just try some different arbitrary numbers until it feels right. We multiply this by Delta Seconds (8) to ensure that the rate at which we fly will be the same on all systems at any frame rate. Add this value to the current Z value (7) and plug the return value from that into the Z input on Set Actor Location. Voila!

Thank you so much! Ill have to try this out when I get home. I’m currently trying to watch more UE4 videos on blueprints so I can figure out this stuff out on my own, but with help like yours it really helps!
Thank you again!

You’re welcome! Let me know how it works out!

The only thing I had trouble with was trying to reference the player pawn, Number 4. How do I call the player pawn node? All I could get was reference player controller and Get player pawn, or something like that.

That’s what you want, get Player Pawn. The reference in my example was just a variable of type Pawn. You can set up this variable by calling “Event Begin Play” which will run right when the object is spawned in the world, calling “Get Player Pawn” and setting that pawn variable as the return value there. The variable is optional though, you can keep using “Get Player Pawn” all around your Blueprint if you prefer.