Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Generate Spline and Segments dynamically with a script??
#1
Ok so I have an ambitious idea where I want to make a dynamic path routing algorithm.  So far I got a script that detects the road texture, tries to find the middle of it, and plops a cube in the middle... then repeats every 30 meters... anyway, instead of a cube, I plan to put a spline control point.  I've only ever made splines with the GUI interface.

I've been fishing around the API and am utterly confused.

Here's the rather simple code I'm using for the middle cubes:
Code:
           midPathMarkers.Add(GameObject.CreatePrimitive(PrimitiveType.Cube));
           midPathMarkers[i].transform.localPosition = new Vector3(xPos, hit.point.y+4, zPos);
           midPathMarkers[i].transform.localScale = new Vector3(4, 4, 4);

Here's what my algorithm currently does.

[Image: XNWJYif.jpg]

I plan to have it detect when you're coming close to a fork in the road and the user will choose left/right.  But you can also press a button and "free roam" with no spline, then press another button and it'll create a new spline to the nearest dirt road and continue with the pathing algorithm. 

It'll be so cool if this works.  I need the simple above, but if you have any other tips or things to keep in mind while doing such a task please let me know!

Thanks
Reply
#2
(08-09-2018, 03:32 AM)mythstified Wrote: I've been fishing around the API and am utterly confused.
Can you please explain to me what confuses you? Do you have any suggestions to make the API easier for you? I ask because I don't see the complexity in finding the method to add control points to a spline. Maybe I became blind to the issues you encountered, so your opinion will be helpful.
The method you are looking for is CurvySpline.Add

(08-09-2018, 03:32 AM)mythstified Wrote: if you have any other tips or things to keep in mind while doing such a task please let me know!
For better performance, use the Add method override that takes the array of all positions at once, instead of calling the one that adds a single CP multiple times.
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Reply
#3
(08-09-2018, 11:42 AM)_Aka_ Wrote:
(08-09-2018, 03:32 AM)mythstified Wrote: I've been fishing around the API and am utterly confused.
Can you please explain to me what confuses you? Do you have any suggestions to make the API easier for you? I ask because I don't see the complexity in finding the method to add control points to a spline. Maybe I became blind to the issues you encountered, so your opinion will be helpful.
The method you are looking for is CurvySpline.Add

Thanks I'll check that out.

As for the API, I think one thing that would vastly improve it is examples.  See Unity's API: https://docs.unity3d.com/ScriptReference...round.html

(08-09-2018, 03:32 AM)mythstified Wrote: if you have any other tips or things to keep in mind while doing such a task please let me know!
For better performance, use the Add method override that takes the array of all positions at once, instead of calling the one that adds a single CP multiple times.

Interesting!  Thanks.  I'm debating whether to premap out all the directions or have it run realtime.. It would probably be more performant though to premap it at the start. Hmm
Reply
#4
Premaping will allow you to tweak/correct things if your automatic process is not perfect. That can be very useful.
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Disable a spline's gizmo when not selected or disabled. mikechr2000 1 139 02-03-2025, 09:34 AM
Last Post: _Aka_
Information Questions regarding spline colliders and collisions with rigidbodies Spyboticer 7 509 01-20-2025, 12:25 PM
Last Post: _Aka_
  Extrude mesh along spline. New and confused user GhostStalker 3 213 01-02-2025, 09:58 AM
Last Post: _Aka_
  Newly created spline is invisible quickytools 7 497 12-21-2024, 10:14 AM
Last Post: _Aka_

Forum Jump: