Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Spline.length incorrect
#1
Question 
Hi, so I'm  creating a sort of road system where I 1st click to set the start of the spline ( CP0000) , I keep mouse button down and buttonup places  the 2nd control point etc.
  After each control point is addded I'm  logging the spline.length but what I've noticed is the spline length isn't correct. It's correct in the inspector but  not when I log it. 
The Gameobject that the spline is a part of is always at 0,0,0.  What I have noticed is after the 2nd control point is added (CP0001) ( this is when I log the spline.length ) the spline length is logged as the dist between 0,0,0 and the CP0000 regardless of how long the spline actually is.
  If I place the Gameobject at the position of CP0000 after placing CP0001 the spline.length is logged as 0 but it's still correct in the inspector.

1. How can I get the acutal spline length please ?
2. Is there a way to get the spline length at each control point.


Regards.
Reply
#2
When a spline is modified, a call to Refresh is needed to update some of its data. This call is done automatically every frame, and in some API methods. Under some circumstances, one might call the Length property while the spline is not refreshed.
Try calling spline.Refresh before doing the log. If the problem persists, please send me a reproduction case (the code doing the cp adding and logging)
I hope this helped
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
Refreshing the spline solved it, thanks.

Sorry for another question but is there a way to get the length at each control point apart from logging spline.length in a list

Cheers.
Reply
#4
You are welcome

yourSpline.TFToDistance(yourControlPoint.TF)

Have a nice day
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to find out whether the spline is self-intersected. mydayz 1 18 Yesterday, 12:08 PM
Last Post: _Aka_
  Lightmaps UV stretched even after setting split length to minimum dartboard 4 324 10-13-2021, 12:05 PM
Last Post: _Aka_
  Control of an object that uses a spline ricke 5 318 09-16-2021, 10:30 AM
Last Post: _Aka_
  Problems with spline prefab topquarkone 3 227 09-15-2021, 08:47 PM
Last Post: _Aka_

Forum Jump: