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;</p>
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?