- Home /
The question is answered, right answer was accepted
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.
Answer by SergeantBiscuits · Jan 26, 2013 at 05:56 AM
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 ad$$anonymous$$ will do so! heh)
quaternions are a hell of a business, eh
Hah, no kiddin! Yeah I'll close it. Thanks boss.
Follow this Question
Related Questions
Allow y rotation 1 Answer
How to make an enemy always face the player.? 1 Answer
How to get a ai to drive to a raycast 0 Answers
What's a good way to find the ground normal? 1 Answer
Raycast Normal in Local Rotation? 1 Answer