How to make a ladder with Blueprint?
I read in another thread that UE4 doesn't have ladder volumes: https://answers.unrealengine.com/questions/7838/ladder-volume.html
I'm guessing I can make a ladder with Blueprint? I started by creating a volume with a mesh that when the player overlaps their location is modified so they're basically teleported upward. That's the first iteration.
The next step would be to instead change the player controller to one that made forward = up and backward = down perhaps? And probably turn off gravity while in that volume? And maybe change the player state to "climbing".
How much of this can I do with Blueprint and what parts would definitely require C++? Any clues on which classes or functions to look at, either in the code or via Blueprint, would be appreciated!
asked Mar 23 '14 at 12:41 AM in Blueprint Scripting
I apologize for the late reply! Here is a quick demo blueprint that can function as a ladder.
I'll explain it step-by-step.
This is running within the player Blueprint. Upon each "Event Tick" (meaning that it runs every frame), a line trace (also known as a raycast) is cast from the player's position to wherever the player is looking. You can see this as "Get Actor Location" is connected to the trace's "Start" input. To make a line cast in the direction that the player is looking, I first grab a reference to the camera that is attached to the player (I'm using the First Person Blueprint Template by the way). Next, I remove the Pitch and Roll information from the Rotator so that the line is cast parallel to the ground (Yaw deals with the X and Y axes, Pitch deals with the Z axis, and Roll is the rotation around the forward vector; if you want to include the Pitch, then the "Break Rot" is unnecessary, although the "Start" input will need to be changed to the Camera's location instead of the Pawn's). "Rotate Vector" effectively converts the Rotator into a Vector, which is then multiplied by 1000, which acts as the length of the raycast. By adding the player's location to the trace, it localizes the "End" to be relative to the player. "Make Array" is there to check for WorldStatic objects, which I assume your ladder will be (moving ladders would be a bit more complicated).
In my scene, I placed a Blueprint Actor that I made that consisted of a StaticMesh that represented the Ladder. In that Blueprint, I set the StaticMesh to be Static (not Stationary or Movable) and in the Defaults tab, I added "Ladder" as a Tag Element (without the quotations).
Back in the player Blueprint, I have a Branch that checks for 1) whether anything was hit, 2) whether the actor that was hit has the "Ladder" Tag (which effectively verifies that the ladder is being looked at, and also allows any object that has a "Ladder" tag to be used as a ladder), and 3) that the player is in a "Falling" state. This prevents the ladder from being activated by simply being close, and requires the player to 'jump' onto the ladder. When all three of these conditions are met, then we move on to the next part, else we reset the gravity back to normal (it hasn't changed yet, but it will during climbing). Next, we check how far from the ladder we are, so that it is only activated when we are close enough. To do this, we grab the "Impact Point" and subtract the player's position from it. The length of the resulting vector is then checked to see if the length is small enough (I have it set at 100 in the Blueprint, but you can set it to any value you want, just remember not to set it too small, else it won't make it past the character's bounds). If it is, then we move on to the next step, else we reset the gravity.
Next, we check to see whether the player is trying to move the player forward, back, or at all. If they're trying to move forward, we convert this movement into positive movement along the Z axis (which moves the player up; I have it set to 500, but you can increase or decrease the speed as you see fit, or make it variable depending on how close to 1 the "Return Value" of MoveForward is). If the player is not trying to move forward, then we check if they're trying to move backward. If so, we set the movement as negative along the Z axis. If the player is doing neither, then we nullify all movement, so that the player stays at their current position. After these steps, we set the gravity to zero, so that the player does not continuously fall when not moving.
This being a quick blueprint that I made, there are quite a few inefficiencies from an optimization standpoint, such as setting the gravity to zero during every frame that the player is on the ladder, and resetting the gravity whenever the player is not on the ladder (which will most likely be the majority of the time). In addition, this blueprint does not handle what to do once the player has reached the top of the ladder. Currently, they will bounce up and down, as once they go over the StaticMesh, gravity will take hold, which will cause them to fall, and reattach to the ladder. An easy way to "pull up from the ladder" would be to have a trigger volume near the top of the ladder that activates when the player enters it, and a timeline that plays that moves the player to the top of the ladder.
I hope I explained everything clearly! I apologize if my grammar is messy in a few places. I'll be happy to answer any further questions that you may have!
answered Apr 15 '14 at 03:10 AM
I may be over-simplifying this somewhat, but thought I would post my solution for ladders here just in case anyone finds it useful. It is extremely simple and quick to set up, and produces exactly the behavior that I wanted. (Though others may want more for their games)
First I created a simple ladder blueprint and in the components tab made the ladder out of meshes in the example content:
Note: make sure that the ladder volume (box component) extends far enough above the ladder mesh to allow the player to step off once reaching the top.
Next create this graph in the ladder blueprint graph tab. It simply sets the players movement mode to flying when entering the volume, and walking when exiting it. (Walking works better than falling as it ensures that the transition at the top looks natural)
Final step in next post since it only allows 2 attachments per response.
answered Jul 23 '14 at 08:23 PM
I got it to work when I mixed Parralex solution with
answered Aug 13 '15 at 08:50 PM
looking over this i cant see any info for animations or to show the difference between the start and end of the ladder so i'm not sure how to use for third person, is this something i could build of this example using a state machine or would going a different route other (than changing the movement mode to flying) be better for my situation? (i have no other use for flying in my project so either way should be ok)
i'de like the jump button to trigger climbing ladders when close enough so i was thinking of making a "is ladder proximity" variable that triggers the start animation although this would likely cause the start animation to play when leaving the ladder. how would i define to start and finish properly in this situation ?
answered Sep 16 '16 at 12:15 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here