Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Orientation in 2D
#1
I'm working with sprites in 2D, so set my CurvySpline to Restrict to 2D. That seems to affect control points but not orientation. The orientation vector does not stick to the same XY plane. So, sprites traveling a curve in 2D get "skinny" on the curves. I'm guessing this also has something to do with how I should be setting my Orientation Source & Target in the SplineController, but I have yet to find a combination that works.

Likewise, changing my CurvySpline orientation from Dynamic to Static, or None, also does not get what I want, although leaves sprite in the correct plane.

Thanks!
Reply
#2
(07-24-2018, 09:54 PM)Livealot Wrote: That seems to affect control points but not orientation.

Yes, Restrict to 2D affects only CPs.This option doesn't modify the inner workings of the spline, but instead just adds restrictions to the editor to make it easier to work on a single plane.

(07-24-2018, 09:54 PM)Livealot Wrote: Likewise, changing my CurvySpline orientation from Dynamic to Static, or None, also does not get what I want, although leaves sprite in the correct plane.

You can set the orientation of each control point the way you want by setting the spline's orientation to Static and then ticking the Bake Orientation option for each control point. You will then be able to define the orientation at a control point by modifying the control point's rotation.

If my answer is not helpful, please send me a scene, or at least screenshots, so I can see what you are trying to do.
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#3
And a Unity related tip, that you might not be aware of: if you want to rotate multiple objects around themselves, instead of around the point positioned in the middle of the group, make sure to set the option bellow to pivot

   
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#4
hmmm, I'm hoping there's a procedural approach rather than having to manually adjust every control point. For context, let's imagine a 2D rollercoaster where the course is procedurally generated. I'm trying to keep the car on the same side of the track regardless of uphill, downhill, or loopDeloop. I've succeeded in created the spline dynamically, and getting the car to follow the spline. But the sprite keeps rotating in 3D space around the 2D spline on some, but not all, curves. When I inspect the spline, it is correct when the spline orientation is on the 2D plane, and incorrect when the orientation blends to 3D.

I'm setting my splineController orientation Source to Tangent and my Target to Forward, which is what I assumed to be the right approach to keep my cars on the correct side of the track. But it seems like the splineController is calculating the tangent from the 3D orientation of the spline for some reason.

In the attached pic, you'll see the car going up the track, and the spline orientation is pointing to the right. Then, instead of continuing to point to the outside of the track , the orientation starts to rotate to the left, which makes the sprite rotate in 3D space ("get skinny") and switch sides of the track.
   

I'm hoping there's a setting I've got wrong, that would keep this in pure 2D procedurally.
Reply
#5
There is a simplar way:
- Set the Orientation to dynamic
   
- Rotate the last control point by 180° on the X axis. You can alternatively give the first control point a swirl on the anchor group of -0.5 turn
   
All the operations above are doable through the API.

Is my answer answer addressing your issue?
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#6
Ok, this seems to be on the right track. yuck yuck. But I need to be able to figure out the rotation procedurally to work for any track design. Since I'm dynamically generating control points as I go, is there a way to lock in the right orientation adjustment at instantiation of the control point?
Reply
#7
The orientation is computed based on control point's rotation, in addition to other factors. So what you expressed as "a way to lock in the right orientation adjustment at instantiation of the control point" boils down to setting the right orientation at the control point's instantiation.

The methods to add control points (CurvySpline.Add, CurvySpline.InsertAfter, ...) have an override to define position at instantiation, but no such override exists for orientation. The created control points will have a default orientation (X=0, Y=0, Z=0). So you will have to modify the orientation after instantiation using CurvySplineSegment's SetRotation or SetLocalRotation.

I think that the rotation of the last control point by 180° (while setting Orientation as Dynamic) should be enough for your case, but if it isn't, then the way to figure out the right control point rotation to set will be something like:
Orientation at N = (Orientation at N-1) * (the rotation between Tangent at N-1 and Tangent at N)
N being a control point on the spline, and N-1 being the previous control point.
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#8
The simple approach of just rotating the last control point only worked for some cases, so I'm trying to find the correct 2D rotation approach for each control point. I am still struggling to translate your pseudo-code recommendation for at least 2 reasons. First, vector math and quaternions always make me queasy. Second, I still don't have a good handle on how best to instantiate control points and set CP rotations vs what Curvy does behind the scenes.

For example, I learned that you can't instantiate and rotate a control point in the same step since there are some functions (GetOrientationFast) that needs the cache from the spline. So I instantiated all the control points first, then ran spline.Refresh, and now am passing back through the spline control points trying to figure out the appropriate orientation adjustment.

Here's my approach, that does not work. What has me struggling is that even when I try to set all the control point orientations to a fixed rotation, they still get twisted into 3D on some curves at run-time. That makes me wonder if my attempts at setting the rotation here are getting overwritten by something else in Curvy.

Code:
//need to refresh after creating control points so the cache is available for GetOrientationFast & GetTangentFast
TrackSpline.Refresh();

//need to rotate each control point in the spline to stay on the 2D plane
for (int i = 1; i < TrackSpline.ControlPointCount; i++) {
Vector3 previousTangent = TrackSpline.ControlPointsList[i - 1].GetTangentFast(0f);
Vector3 nextTangent = TrackSpline.ControlPointsList[i].GetTangentFast(0f);

Quaternion previousRotation = TrackSpline.ControlPointsList[i - 1].GetOrientationFast(0f);

Quaternion adjustment = previousRotation * (Quaternion.FromToRotation(previousTangent, nextTangent));

TrackSpline.ControlPointsList[i].SetRotation(adjustment);
}

TrackSpline.Refresh();
Reply
#9
(07-29-2018, 09:31 PM)Livealot Wrote: I learned that you can't instantiate and rotate a control point in the same step since there are some functions (GetOrientationFast) that needs the cache from the spline.

This is no more the case. Methods that add control points to a spline now make sure that the spline cache is up to date. Which version of Curvy do you use?

(07-29-2018, 09:31 PM)Livealot Wrote: What has me struggling is that even when I try to set all the control point orientations to a fixed rotation, they still get twisted into 3D on some curves at run-time.

Either set your spline's orientation to Static, or if you wan to keep it as Dynamic, set to true the Orientation Anchor value for the control points which rotation you define.
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#10
I'm a new user, so the version I got from the Asset Store was 2.3.0

Ok, so it sounds like using Dynamic orientation is what battles with my instantiation script. So I'll try it with Static orientation after manually setting each control point orientation to the right angle of the tangent and setting  SerializedOrientationAnchor to true

Thought I'd pass along some visual examples of what dynamic orientation was doing in 2D when all the control Points are set to orientation anchors and rotations are left at default. I'm sure there's a pattern there somewhere, but I couldn't figure it out.

       

       

   
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Shapes points orientation itsGama 3 8 01-18-2023, 02:51 PM
Last Post: _Aka_
  2d - orientation looping_co 1 5 09-01-2022, 04:17 PM
Last Post: _Aka_
  Spline controller orientation itsGama 4 30 01-24-2022, 06:38 PM
Last Post: _Aka_
  Regarding static orientation mydayz 10 287 12-05-2021, 01:25 PM
Last Post: _Aka_

Forum Jump: