- Home /
how to grab ledge and climb up
Hi i am using a rigidbody controller and i want to make the player be able to go next to a wall, jump, then latch on the edge and only climb up if u press w. How can i do this thanks?
Answer by Fornoreason1000 · May 01, 2013 at 08:21 PM
there are lots of ways on going about this... one way is to use heavy ray casting to determine if the ledge is "grabbable" by checking its height then setting the players Animation and position accordingly. you could also do it but adding tags to the walls you want climb and and checking if the player is near enough to the walls and jumping high enough to grab on. you could use empty markers to position the players handles more realistically. you probably need to strategically model these edges for this purpose.
personally i would use a combination of the last two i mentioned. that way by using the marks and player positioning and can grab on to edges that are hanging over like a collapse bridge. it also allows me to make certain edges un-grippable, like electric fences.
one you have determined the edge to be scaled, you can then check for the W input to make them grab hold. to make them do this, just make an animation and lerp them toward the edge. to stop them from falling you can turn off gravity or add an opposite force .
now you may want them to move side to side, this gets a little harder but they empty markers become allot more useful here. as they can direct if the player can go there or not. and more importantly rotate and re position the hands when shift around rounded edges.
now to make them climb up... this can be easy, depending on you game design. personally id make the game check if you can actually climb up it, in case your holding on like a pipe or a small ridge and you player doesn't to climb up on it lol. you can do this by raycasting some more. if its clear and the player can proceed, just make a animation the make the player jump/climb up while moving them off from the edge(so they don't fall back down), once there on there feet you can re-enable gravity or disable to anti gravity force i mentioned earlier help it helps
Ray casting:
http://docs.unity3d.com/Documentation/ScriptReference/Physics.Raycast.html
http://docs.unity3d.com/Documentation/ScriptReference/Plane.Raycast.html
http://docs.unity3d.com/Documentation/ScriptReference/NavMesh.Raycast.html
http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.AddForce.html
http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody-useGravity.html
thank you, but i am not an experienced coder :( I do not know "lerp" and my attempts at scripting an animation are terrible. I have little experience with raycasting also :(
$$anonymous$$y suggestion would be to become a more proficient coder, and to learn the Unity API, before you attempt more complex actions like this. Practice your animation skills, raycasting, and translating of rigidbodies around the game world for a bit. Think up different scenarios, and try to achieve them. Have fun along the way, and don't take such a rigorous approach to building your concepts; in other words, allow yourself to feel free and to play while learning.
Answer by jonnytracker · Jun 22, 2020 at 12:42 AM
I tried this with climbing animation. And it snaps back to old position. Like the physics collider is not following the climb animation
I've been through the same problem while trying to make a ledge climb system. So, I'm guessing that you probably have Root motion enabled on your character climb animation. Due to this, the skeleton of your character is moving but the colliders or the controllers are not. I fixed this by transitioning to a Crouch animation once the climb animation is over and then moving my character (it's transform to the desired position) I made an empty child object and set it's local position to what I needed and then translated to this pos with a script. Both of these are happening in the same video frame.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Play Two Animations Simultaneously using Animator 2 Answers
Need help with some OnTrigger Scripting 2 Answers
Creating an animated raising "force field"? 1 Answer
Why is my animation not being played? 0 Answers