Search Unity

Bug my player is not attached to the wall when he's climbing

Discussion in 'Scripting' started by elahidri, Nov 29, 2022.

  1. elahidri

    elahidri

    Joined:
    Aug 18, 2021
    Posts:
    1
    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?
    Code (CSharp):
    1. var vi = Input.GetAxis("Vertical");
    2.          var h = Input.GetAxis("Horizontal");
    3.          var move = transform.up * vi + transform.right * h;
    4.          m_Animator.SetBool("Climb", true);
    5.          m_Animator.SetFloat("H", move.y, 0.1f, Time.deltaTime);
    6.          m_Animator.SetFloat("V", move.x, 0.1f, Time.deltaTime);
    7.          m_Animator.applyRootMotion = true;
    8.           rb.velocity = transform.up * vi*0.5f + this.transform.right * h*0.5f ;
    9.          Vector3 v = (m_Animator.deltaPosition) / Time.deltaTime;
    10.          rb.angularVelocity = Vector3.zero;
    11.          transform.rotation = Quaternion.LookRotation(frontWallHit.normal * -10f);
    12.          rb.useGravity = false;
    13.          pm.m_GroundNormal = Vector3.up;