Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rotating along z axis
#1
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.

 

 


Attached Files Thumbnail(s)
   
Reply
#2
(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);
}

 
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Mesh problem in generator after rotating control points ATHellboy 1 1,687 02-10-2020, 11:24 AM
Last Post: _Aka_
  Moving freely on the Y axis? clearleaf 6 5,196 01-30-2020, 11:21 AM
Last Post: ATHellboy
  y axis rotation flowerfire 1 3,504 12-22-2016, 08:14 PM
Last Post: Jake
  Weird anomaly when crossing an axis richadam 4 7,202 10-12-2015, 07:07 PM
Last Post: richadam

Forum Jump: