Hi,
is there any way to make tihs expression work in world space please ?
leftHandPos.z = leftFootpos.z - leftHandOffset.z;
Thanks
Hi,
is there any way to make tihs expression work in world space please ?
leftHandPos.z = leftFootpos.z - leftHandOffset.z;
Thanks
OK some explanations :
the goal is to make the avatar climbing a block (in an other time he will slide his hands on the edge) using IK.
tha problem is that the hands positions are not the same depending of the rotation of the avatar.
i post 3 captures. the 1st one is just to see the raycasts. red ones are for feet targeting and placement.
the green ones for hands.
in the 2nd capture the player is in (0,0,0,) rotation. it works quit good (for a first load lol)
in the third (rose cube rotation ( 0, 180, 0 ) ) the feet are ok but not the hands… and if i invert the sign of the offset it works but not in (0,0,0) rotation.
thats my problem. how to make this offset work in all directions.
this is the part of code that set up feet and hands positions on the “wall”
// left Hand IK Check
if (Physics.Raycast(transform.position + transform.TransformDirection(new Vector3(0f, 3f, 0.5f)),
transform.TransformDirection(new Vector3(-0.5f, -1f, 0f)), out LHit, 1.5f))
{
leftHandIK = true;
leftHandPos = transform.TransformVector(LHit.point - leftHandOffset);
leftHandPos.x = curLeftHandPos.x - leftHandOffset.x;
leftHandPos.z = leftFootPos.z - leftHandOffset.z; // on se calque sur les pieds pour la progression des mains
leftHandRot = transform.rotation * Quaternion.FromToRotation(Vector3.forward, transform.TransformDirection(LHit.normal));//Quaternion.FromToRotation(Vector3.forward, LHit.normal);
}
else
{
leftHandIK = false;
animator2.SetBool("PhysicJump", false);
useIK = false;
}
// Right Hand IK Check
if (Physics.Raycast(transform.position + transform.TransformDirection(new Vector3(0f, 3f, 0.5f)),
transform.TransformDirection(new Vector3(0.5f, -1f, 0f)), out RHit, 1.5f))
{
rightHandIK = true;
rightHandPos = transform.TransformDirection(RHit.point - rightHandOffset);
rightHandPos.x = curRightHandPos.x - rightHandOffset.x;
rightHandPos.z = rightFootPos.z - rightHandOffset.z; // on se calque sur les pieds pour la progression des mains
rightHandRot = transform.rotation * Quaternion.FromToRotation(Vector3.forward, transform.TransformDirection(RHit.normal));
}
else
{
rightHandIK = false;
animator2.SetBool("PhysicJump", false);
useIK = false;
}
// left Foot IK Check
if (Physics.Raycast(transform.position + transform.TransformDirection(new Vector3(-0.3f, 0.6f, 0f)),
transform.TransformVector(Vector3.forward), out LFHit, 0.5f))
{
if (leftHandIK) leftFootIK = true; // Evite que les pieds partent avant les mains
leftFootPos = LFHit.point - transform.TransformDirection(leftFootOffset);
leftFootRot = transform.rotation * Quaternion.FromToRotation(transform.TransformVector(Vector3.up),
transform.TransformDirection(LFHit.normal)) * leftFootRotOffset;
}
else
{
leftFootIK = false;
animator2.SetBool("PhysicJump", false);
useIK = false;
}
// Right Foot IK Check
if (Physics.Raycast(transform.position + transform.TransformDirection(new Vector3(0.3f, 0.6f, 0f)),
transform.TransformDirection(Vector3.forward), out RFHit, 0.5f))
{
if (rightHandIK) rightFootIK = true; // Evite que les pieds partent avant les mains
rightFootPos = RFHit.point - transform.TransformDirection(rightFootOffset);
rightFootRot = transform.localRotation * Quaternion.FromToRotation(transform.TransformDirection(Vector3.up),
transform.TransformDirection(RFHit.normal)) * rightFootRotOffset;
}
else
{
rightFootIK = false;
animator2.SetBool("PhysicJump", false);
useIK = false;
}
Thanks for help.
A transform has the methods TransformPoint and InverseTransformPoint. They transform coordinates from local to world, and world to local, respectively.
Is that enough to get you there?
It’s already being done in world space.
I do wonder why you’re using different functions for left and right hand position though. Lefthand is using transform.TransformVector while righthand is using transform.TransformDirection.
Assuming leftHandOffset and rightHandOffset are in local space, you need to transform them to world space and then subtract. So…
leftHandPos = transform.TransformVector(LHit.point - leftHandOffset);
rightHandPos = transform.TransformDirection(RHit.point - rightHandOffset);
Should be:
leftHandPos = LHit.point - transform.TransformDirection(leftHandOffset);
rightHandPos = RHit.point - transform.TransformDirection(rightHandOffset);
Hi and thanks for your answers.
jimroberts : i tried many methods to see if it fix the issue.
and both of transform.TransformDirection() transform.TransformVector() have the same effect…
Baste : i will try with InverseTransformPoint in few hours and tell you.
thanks guys ![]()
Same result with InverseTransformPoint() (im not surprised :))
hum… it seems not possible this way. the problem is the use of Offsets to adjust hands positions.
too bad ! it was too close …
must find another way Alex ![]()
thanks jimroberts & Baste
Are your offsets in local space or world space? This makes me think the offsets need to be transformed with the rotation of the character
yes you’re right but i found no any method to transform axis by axis (on x and z axis)
Couldn’t you multiply your offsets by the characters normalized rotation vector?
it seems working this way. Not in all rotations yet. but in (0,0,0) and (0,180,0) it works. we maybe have a lead ![]()
// left Hand IK Check
if (Physics.Raycast(transform.position + transform.TransformDirection(new Vector3(0f, 3f, 0.5f)),
transform.TransformDirection(new Vector3(-0.5f, -1f, 0f)), out LHit, 1.5f))
{
leftHandIK = true;
leftHandPos = LHit.point - transform.TransformDirection(leftHandOffset);
float xLHAdjust = Mathf.Cos(transform.localRotation.eulerAngles.y);
leftHandPos.x = curLeftHandPos.x - (leftHandOffset.x * xLHAdjust);
float zLHAdjust = Mathf.Sin(transform.localRotation.eulerAngles.y);
leftHandPos.z = surfaceHit.point.z - (leftHandOffset.z * zLHAdjust) ;
leftHandRot = transform.rotation * Quaternion.FromToRotation(Vector3.forward, transform.TransformDirection(LHit.normal));
}
Long is the noob pathway ![]()