- Home /
How to handler rotation of a Gameobject while aligning it with normals
I'm trying to move a GameObject along a bumpy cylinder while it follow the surface normals. I do this with the following code.
if (Physics.Linecast(Squid.transform.position, target, out hit)) {
Squid.transform.position = hit.point;
Squid.transform.rotation = Quaternion.FromToRotation(Vector3.down, hit.normal);
Vector3 rotSquid = Squid.transform.rotation.eulerAngles;
float correction = 90 - rotSquid.x;
print(correction + rotSquid.x);
print("correction " + correction);
Squid.transform.Rotate(Vector3.down, correction);
}
As you perhaps can see I'm trying to let the object to look in one direction by getting the x en rotating it back to 90 degrees. But this seems to fail helplessy. I have tryed some other things but all without the desired result.
Anyone here has any idea?
Answer by Max Kaufmann · Aug 02, 2010 at 05:46 PM
Use Quaternion.LookRotation with the normal for the "up" direction.
Your answer
Follow this Question
Related Questions
(Solved) Aligning player to surface while still maintaining look direction 1 Answer
2D animation : problem with rotation interpolation 1 Answer
Edited mouselook script rotation clamp not working 0 Answers
Code to rotate around a local axis until local Y is 0? 0 Answers
Rotation problem while dynamically changing animations 2 Answers