Set Quaternion to another Quaternion, but oriented along

Hey guys, quick question–

I am trying to stick a robot’s foot to the terrain but I am having trouble laying it flat. I am using a raycast firing down into the terrain which gives me the hit.normal, the z-axis of which points upwards. I want the foot to stick to the hit point but have its y-axis pointing up along the normal. I also want the foot to rotate along its y-axis to the same angle as the robot.

So basically I’m thinking I need to do this (pseudocode):

foot.rotation = hit.normal(along z axis); // This is what I can't figure out
foot.eulerAngles.y = robot.eulerAngles.y;

I’m sure there’s a simple way to do this. Thanks for the halp! You guys own.

foot.rotation = Quaternion.LookRotation(robot.forward, hit.normal) works for the y and z rotations, but the foot does not slope 'downwards' or 'upwards', that is, the x rotation remains locked at 0.

1 Answer

1

Managed to get it workin well enough by firing off two raycasts, one from the back of the foot and another from the front, then doin:

Quaternion.LookRotation(footFrontHit.point - footBackHit.point, footBackHit.normal);
foot.transform.eulerAngles.y = robot.eulerAngles.y;

Hey Sarge! You might be best to close or delete this question ('asked and answered") (or some rude admin will do so! heh) quaternions are a hell of a business, eh

Hah, no kiddin! Yeah I'll close it. Thanks boss.