0

I am building a free climbing system for a 3d Game like in Genshin Impact but I can't get my player to climb up the edge,

I used double raycast to detect if it's an edge or not, if there is an edge, the animation is triggered and I used matchTarget as shown here

private bool edgeDetect()
    {
        RaycastHit firstHit;
        Vector3 position = transform.position + detectionOffcet;
    if (Physics.Raycast(position, transform.forward, out firstHit, 2f))
    {

        if (Physics.Raycast(firstHit.point + (transform.forward * playerRadius) + (Vector3.up * 0.6f * playerHeight), Vector3.down, out var secondHit, playerHeight))
        {
            Targetposition = secondHit.point+edgeOffcet;
             m_Animator.SetTrigger("edge");
            Vector3 climbEnd = secondHit.point;
            m_Animator.MatchTarget(climbEnd, Quaternion.LookRotation(-firstHit.normal), AvatarTarget.Body, new MatchTargetWeightMask(Vector3.one, 0), 0, 0.09f); 
          return true; 
        }
    }
    return false;
} 

but this is not working properly, the player always falls and does not reach the edge, he gets stuck , Also if the wall is diagonal the detection system will be wrong, how how can I fix this

Dev
  • 1
  • 3
  • Regarding your first problem of the player always falling when reaching an edge: Where is the code that moves the character from hanging at the side of the cliff to standing on top of it? If that's all the code you have, then you probably still need to add that. – Philipp Feb 16 '23 at 14:27
  • Regarding your second problem: Have you been able to reproduce the exact circumstances that cause the player to "get stuck"? I would assume that it probably works on a plain vertical wall (does it, though?) but fails when trying to climb a more complex one. What complexities exactly lead to the problem? – Philipp Feb 16 '23 at 14:27
  • @Philipp am I supose to add a code with the match target I though the match target will do the job. and yes it works fine on vertical wall , I guess because the raycast is towords down – Dev Feb 16 '23 at 14:36
  • it is the match Target that gets the player to be stuck because it does not reach the destination so the player stays flighying and moving by it self and can't do anything – Dev Feb 16 '23 at 14:42
  • Maybe you are re-enabling gravity too early? You probably shouldn't do that before the character completed the "edge" animation. – Philipp Feb 16 '23 at 14:43
  • I added a climb up beheviour to the edge animation and I reactivated the gravity in OnStateExit – Dev Feb 16 '23 at 14:52
  • if you have any other solution on how to climb the edge please let me know – Dev Feb 16 '23 at 14:54
  • I ll look into that – Dev Feb 17 '23 at 12:26

0 Answers0