0
\$\begingroup\$

I am trying to create a climbing system from my 3d game, player will be able to climb anything like terrain tree rocks, or whatever. I managed to get the player to climb but unfortunately when he climbs he is not attached to the wall, his hands are in the air close to the wall it's like he is grabbing in the air, and his knees go inside the wall. I tried using IK, and it worked to get the player's hands attached to the wall, but it overrides the animation so the hand is always attached to the wall and doesn't animate
this is the code for the climbing part what am I doing wrong?

 var vi = Input.GetAxis("Vertical"); var h = Input.GetAxis("Horizontal"); var move = transform.up * vi + transform.right * h; m_Animator.SetBool("Climb", true); m_Animator.SetFloat("H", move.y, 0.1f, Time.deltaTime); m_Animator.SetFloat("V", move.x, 0.1f, Time.deltaTime); m_Animator.applyRootMotion = true; rb.velocity = transform.up * vi*0.5f + this.transform.right * h*0.5f ; Vector3 v = (m_Animator.deltaPosition) / Time.deltaTime; rb.angularVelocity = Vector3.zero; transform.rotation = Quaternion.LookRotation(frontWallHit.normal * -10f); rb.useGravity = false; pm.m_GroundNormal = Vector3.up; 
\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

You've picked a hard nut to crack. Climbing on arbitrary surfaces can be quite tricky. Especially considering all the (sometimes literal) corner cases you have to be aware of. So I can't give you a copy&paste code solution which is just going to work for anyone. I can only provide some advise how to figure one out of your own.

Using IK is certainly the right way to do it. But keeping the IK weight at 100% with a static IK position isn't going to work because, as you noticed, it permanently glues the hand/foot to the target. You want that through some phases of the climbing animation, but not all of them. The solution can be to change the IKWeight of each limb during the animation.

  • 1.0 weight during the phase where the character is grabbing the hold
  • gradually reduce it to 0.0 during the let-go phase
  • Set the new IK target to the next grab position while the weight is 0.0
  • gradually increase it to 1.0 while the character starts grabbing again

Another strategy is to keep the hands and feet under 100% IK at all times but move their IK targets. That requires a script that determines the position of each new hold on the climbing surface and then, when changing from one hold to another, interpolates the positions between them. Yes, that means that you basically do most of the climbing animation via code instead of in your animation program.

A good way to do either is to create a new MonoBehaviour which exposes the IK targets and IK weights (and probably also IK hints) of the animator for all 4 limbs as inspector properties. You can then create animation actions within Unity for those properties and put them on a separate layer of your animation controller. That way you can tweak the IK weights during the animation using curves.

You might also want to take a look at the new animation rigging system. It is an alternative IK system that provides a lot more flexibility. It allows you to implement IK for any bone, not just hands and feet. It also has some interesting specialized IK controllers. For example, the Multi-Position Constraint could be useful to gradually shift between different climbing holds.

\$\endgroup\$
7
  • \$\begingroup\$ Thank you, Philipp, as I am new to gaming development this sounds a bit complicated to me, but I ll try to make it work \$\endgroup\$ Commented Nov 29, 2022 at 10:01
  • \$\begingroup\$ @Dev This is definitely not beginner stuff. Especially if you want to be able to climb on anything and not just flat walls. Just the logic to figure out the ideal hold positions on a polygon collider at runtime makes me scared. If a producer would request this feature from me, then my response would be to estimate at least two weeks to try out a couple things and see what I can come up with. Or hit the asset store and see if there is an existing solution that fits our use-case. This one maybe? \$\endgroup\$ Commented Nov 29, 2022 at 10:21
  • \$\begingroup\$ yeah, it seems not easy, there is no one besides me to do it and I can work with paid assets. so I have to try my best. I will try to get something out of it you already game me an idea thank you for that \$\endgroup\$ Commented Nov 29, 2022 at 11:46
  • \$\begingroup\$ another thing I want to ask you about. it seems that when I climb up the player is going away from the wall end ends up falling because Raycast no longer detects the wall, do you know how can I fix this \$\endgroup\$ Commented Nov 29, 2022 at 14:49
  • \$\begingroup\$ @Dev The obvious solution appears to increase the distance at which the raycast detects the wall. You probably might want to set that higher when the player is already in climb mode than you do when you check if they can enter climb mode. \$\endgroup\$ Commented Nov 29, 2022 at 14:53

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.