Ledge System Problem

Hi everybody,

I have a some code who let me grab one ledge trigger and move along axe X, All work fine if my trigger have 0 rotation on Vertical, but if i rotate the trigger ledge my character have offset on position X after grab.

Because my poor english i up a graphic for u know my probleme

Black cube are forward view of my trigger ledge
The blue cube is my char before jump and grab;
The Green cube is succes pos X
The red are fails ( only if vertical inclinaison )

Any idea ?

  private float AngleDir(Vector3 fwd, Vector3 targetDir, Vector3 up)
    {
        Vector3 perp = Vector3.Cross(fwd, targetDir);
        float dir = Vector3.Dot(perp, up);

     
            return dir;
    
    }

private IEnumerator StickOnLedge()
    {
        if (!ledge)
        {
            ledge = true;
            actorRigidBody.useGravity = false;
            actorRigidBody.velocity = Vector3.zero;

            float positionX = AngleDir(transform.TransformDirection(Vector3.forward), curLedge.transform.position - transform.position, transform.TransformDirection(Vector3.up));

            Vector3 _ledgeAxeZ = (curLedge.transform.position - curLedge.transform.forward * 0.25f);
            Vector3 _ledgeAxeY = (-curLedge.transform.up * 2.1f);
            Vector3 _ledgeAxeX = -curLedge.transform.TransformDirection(Vector3.right * 1) * positionX;
            Vector3 _axes = _ledgeAxeZ + _ledgeAxeY + _ledgeAxeX;
            Vector3 _posActor = _axes;
            transform.position = _posActor;
        }
......... other line codes not important
}

Vector3 _ledgeAxeY =(-curLedge.transform.up* 2.1f);

this line is using the ledge’s “up” direction, the way you seem to have setup the ledge this is always going to be perpendicular to the ledge (hence the “offset”).

If you want the player to jump vertically “up” in terms of the world axis this line would need to be “Vector3.up”. However, changing this will most likely mean you’ll need to change the other lines too.

FYI

transform.TransformDirection(Vector3.forward)
// can just be written as
transform.forward

Ok i see
I change by your Ref and now work perfectly, i really need lern more about this vector world local forward …
A big thx to you and have a nice day.