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
}