03-25-2014, 02:03 AM
(03-24-2014, 10:31 PM)'jose' Wrote: Hi there, I am having a problem. This is the situation: I have a 2d rectangle and I need it to follow a spline (drawn over the edege of a curving, continous terrain). I use the SplineWalkerDistance script as a base, but I need the rectangle to rotate only around the z axis. So if for example the terrain curves up 40 degrees, the rectangle rotates around the z axis 40 degrees. I am trying to use this code (the rest of the script is the same as the original), but it is not working.
Code:if (SetOrientation) {
Quaternion tan = new Quaternion();
tan = Spline.GetOrientationFast(tf);
transform.rotation = Quaternion.Euler(0f,0f,tan.z);
Dir = dir;
}
I'm probably not understanding how transform works in unity, or how GetOrientationFast works, but I've read the documentation and I just can't figure out how to do it.
Thank you
Ps: I have attached a screen capture to ilustrate the problem.
I finally figure it out (kind of) so here it is for anyone that may find it usefull (I mixed up the returns of curvys functions with my poor coding skills, but finally I have it working.)
Code:
if (SetOrientation) {
Quaternion tan = Spline.GetOrientationFast(tf);
tan.y=0;
tan.x=0;
transform.rotation = Quaternion.Slerp(transform.rotation,tan,Time.deltaTime*rotationDamping);
}