Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Bamfax · Jul 16, 2017 at 11:29 AM · pathorientationsplinefollow pathorienttopath

Orientation along spline path / Mesh extrusion along path, problem with smooth orientation

Hello fellow Unity coders,

trying to follow a spline path (to extrude a mesh along it later on), I am having a issue which has caused me some headache for a while now: I am using a base mesh segment which is rotated to match the path tangent/derivate. The base segments' default normal orientation is upwards. While walking the path, the segment is rotated to match the spline tangent. This works fine, but when the tangent is pointing down / the segment is oriented downwards, this introduces orientation spinning on the Y axis when traversing the path further downwards, due to the quaternion rotation trying to find the best/shortest rotation axis.

The code used is very simple:

for (int segmentNo = 0; segmentNo < segmentCount; segmentNo++)
{
    t = segmentNo * step;
    arrowHandles[segmentNo].transform.position = splineCatlike.GetPoint(t);
    arrowHandles[segmentNo].transform.up = splineCatlike.GetDirection(t);
}

This picture illustrates the problem. The grey quads are test segments, which should be replaced by a mesh in the future. The pink arrow is the quaternion axis on which is rotated. The red, blue, green arrows are showing the quad orientation (EditorHandle-alike, better shown in the second picture). alt text alt text

I am trying to keep the code for the segment rotation calculation independent / atomic (not relying on previous segment calculations), to allow the the segment calculation to carried out in random order.

I tried several approaches, some were ok, but all come with downsides (as I am still quite new to this):

  • Ditching quaternion rotation and lerping along fixed forwards for forward, right, up path orientation. This gives a very stable orientation, but has ugly transitions along path curves / turns. If the transitions would be smoother, this would be fine.

  • Using quaternions, but fixing the segment.forward on a world.forward (and lerping between both) fails, as the downward quaternion can have different forward orientations, depending on how the path was oriented before going into the downward slope.

  • Maybe sampling the forward of the path part which is downward pointing, and keeping the segment forward aligned to the averaged forward would work. But this does not sound like clean code.

Thanks for your help, Bamfax

splineorientationproblemswithcomments.jpg (150.9 kB)
splineorientationproblemsshowhandles.jpg (44.5 kB)
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bamfax · Jul 19, 2017 at 03:59 PM 0
Share

I figure that orientation along a spline path does not come by itself, or by just relying on the quaternion rotation (to align the forward with the curve tangent), and it magically figures out were the normal should be.

I added now normals to the control points and lerp on the curve legs between them. This works better. See the following picture: Orange arrows are control point normals, pink arrows are lerped in between.

alt text

It also shows that the curve/spline/path needs to be thought of like a airplane path, where rolling/banking occurs where the path is bending. This also means that there needs to be some continuity, as the banking on a certain position depends on the previous position.

This makes it more difficult to calculate a single bone / base segment independently from others. $$anonymous$$y intention was to have the base segment calc being atomic / independent, so they can be done in no special sequence.

So this will involve some more thinking, how the orientation along the tangent could be calculated.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Bamfax · Jul 19, 2017 at 12:19 PM

I finally found solution this fits this case. The idea here was:

  • First, to have an automatic orientation along the Y axis. The logic should come up with a decent orientation, no user input required (e.g. user laying out a racetrack manually). It does not need to be pretty, it just shouldn't be superugly.

  • Second, to allow calculation of the interpolated base segments without a specific order, not having to care about continuity along the path.

Here is how it looks now. The rotation spinning along the Y axis when the path is going downwards is gone:

alt text

The solution is based on the assumption that every path is curvy, and if it's not, we can just fill up with the previous, next or a default normal (ok, some continuity in here - but ok, since its only done for four control points). This assumption allows to understand a control point introducing a curve as sweeping a plane(triangle) with that curve. On that plane we can put a normal on (simple vector cross). This cross also has the max flip on the Y axis from control point to control point limited to 180 degrees. That can probably be handled as an edge case, or with throwing lots of interpolated segments at it.

In the above picture the algo just chooses the triangle plane edge points in the middle of each spline leg.

It could probably be a lot nicer by introducing normal sampling depending on the curve radius. And the normal could probably also serve as basis for calculation a nice airplane flight path with accurate yaw. If someone has good ideas for accomplishing that, I'd be happy to hear from you.

[2]: /storage/temp/97939-splineorientationlerplegs.jpg


splineorientationproblemssolved.jpg (80.8 kB)
splineorientationlerplegs.jpg (86.4 kB)
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

67 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

ITween orienttopath x-y-z? 1 Answer

Dynamically Add Points to Spline 1 Answer

GameObject to follow another GameObject through a spline with a dynamic end waypoint 0 Answers

How to place collectables along a path 1 Answer

Cloning An Object Along A Path Between 2 Points 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges