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 digzelot · Dec 04, 2018 at 05:14 AM · 3dpathworldspacepercentage

How to find % along path between N points

alt text



When the Move() function is activated, the player runs from "start" to "end" while hitting each point in 3d space along the way. IE, he auto runs from point to point until he reaches the end.

These points are Vector3 world positions: Player movement works fine.

What I need to do is figure out the percentage along this path the player is at every frame and feed that value into a Lerp which is driving my camera - so the value should be between 0 and 1

The total distance of the path is easy, lets say it's: float totalDist = 100.0f;

I could find "percentDist" with: percentDist = currentDist / totalDist;

problem with this method:

I'm not sure how to accurately/efficiently find currentDist every frame

I've been at this for 3 days now which tells me there's probably a wicked easy solution I'm missing. Any ideas?

path.jpg (205.5 kB)
Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Nebukam · Dec 04, 2018 at 06:24 AM

Easiest solution : Go with a Catmull Rom spline equation, which will give you a super smooth camera movement. If you don't have time to go through the concept, just use the life saving Unity 3D Math classes by Bit Barrel Media. You're looking for the method GetPointOnSpline Important note : there's a catch with the Catmull Rom equation, you'll need an extra point at the beginning and end of the spline for correct calculations, but you can easily work around that :)

Googling a bit will lead you to this implementation with a few more utility functions for tangents etc.

Happy coding !

Comment
Add comment · Show 2 · 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
avatar image digzelot · Dec 04, 2018 at 06:43 AM 0
Share

Thanks for your reply, this looks interesting, I'm excited to look into it some more, unfortunately on the surface im not sure this answers the question..

The camera does not follow the path here, only the player does. When $$anonymous$$ove() is called, the camera lerps from "where ever it currently is", back to the end point: the time this transition takes should be the time it takes the player to move from start to end. (The player can move the camera independently from the player, but on $$anonymous$$ove(), the camera needs to reset itself)

avatar image Stephen_O · Jan 09, 2020 at 09:32 AM 0
Share

Thanks, I was looking for the GetPointOnSpline method.

avatar image
0

Answer by hexagonius · Dec 04, 2018 at 06:35 AM

One: you're not dividing by zero. you're dividing zero by distance, which is fine
Two: solved by one
Three: run a loop through your directions. divide each ones magnitude by the total distance. modulor that with your current percentage. if the result is 0, multiply the current distance to the already moved distance (if none, start with adding to the start position). if the result is larger than that, add the full direction and subtract it's percentage from the total and repeat with the next.
if course this can be rewritten with incremental steps so you don't have to run through all directions all the time.

Comment
Add comment · Show 1 · 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
avatar image digzelot · Dec 04, 2018 at 07:16 AM 0
Share

Yeah good point, I'm not sure where the divide by zero error was co$$anonymous$$g from... Edited

Having a hard time understanding your answer for issue three but thinking about these line segments as magnitudes gives me another idea

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

113 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 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

Need to find a point in a line using a percentage and a Vector3 list. 1 Answer

Trouble again with 3D ellipse {FIXED} 1 Answer

how to set an object on a path,how to set an object on a track 0 Answers

Generating a Random Linear Pathway 1 Answer

UI - Best method for Scene UI elements 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