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?
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/NavMesh.Raycast.html
I tried this with climbing animation. And it snaps back to old position. Like the physics collider is not following the climb animation