Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 yotingo · Nov 02, 2017 at 06:56 AM · programmingprocedural

Difficult path logic

I am attempting to create a procedural path from point A to point B. In the end I want it to be a spline, but right now I'm just trying to generate the points at least (I know splines are a big project, beyond the scope of a this thread).


It will be a Harry Potter vs. Voldemort wand dueling type of effect. Random lightning is one thing, but this has some very specific requirements.

Requirements

  • The path will be a minimum length from point A to point B; even if A and B are closer than minimum distance.
    • The path will not pass through obstacles.

    • The path will not follow the terrain (random height is okay) and will not pass into terrain.

Here is an diagram a created to illustrate: alt text

I have been trying to figure this one out for weeks, please let me know if you have any advice. Thanks!

curvedline.jpg (154.7 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

1 Reply

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

Answer by vazor · Mar 12 at 08:46 PM

One way to approach something like this is to start with the two data points, add in a customizable parameter for step_length, and then labels or layers to tell when you are colliding with an obstacle.

Then, you have a function that plots the points. If your wiggle design in the second example is meant to be an oscillating wave of some kind, you can do a trig transform to determine the direction. So for the first step through your code loop, you would subtract points B-A to get a vector from a to b. Then scale it down to the step_length. Then rotate it up or down based on where you are in the total length (step_length times iterations count divided by distance between A and B). That gives you one small step along your ideal path.

Next, you check your new point to see if it collides with the ground or an obstacle. You can usually use a collision test API for this, along with layers/labels to only collide with the right things. If you don't collide with anything, great, save that point in your path data and move to the next iteration. If you DO collide with something you need to avoid, then you need to modify your rotation up or down until it is no longer colliding. You can do a ray test or just adjust it by some amount and keep rechecking until it is clear. This is the very basic approach and is prone to all sorts of edge cases and bugs. A good collision avoidance algorithm or a navigation mesh can help.

But in general that is the approach I would take. I'm sure there are other options though. Good luck!

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 yotingo · Mar 12 at 10:06 PM 0
Share

Thanks for the answer!

That sounds like a great approach. How would you use it to maintain a consistent path length regardless of distance to target? So if the target is 5 meters away, the path will still be 10 meters long.

avatar image vazor yotingo · Mar 13 at 04:35 AM 1
Share

That depends on what you settle on as your wiggle design. For a trig function, you can simply scale up the amplitude e.g. to make a bigger sine wave. You could also try using a per-step weight that adjusts your up/down rotations to be larger based on the ratio of target length vs A-B distance length. A final thought might be to use physics systems- I imagine a library that handles spring joints might work, and then you can apply some forces up and down to the 1/4 and 3/4 joints along the chain to get a wiggle pattern. This physics approach might be more appropriate if the fixed length is more important than a smooth curved shape.

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

81 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

Related Questions

Multiple Cars not working 1 Answer

Hint joint how to configure 0 Answers

Hint Joint like a rope have weird behavior 1 Answer

Procedural Terrain - Diamond Square Algorithm 1 Answer

Generate FTL style star map 0 Answers


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