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
Bug Changing spline connection in inspector causes splines to revert to defaults lacota 3 6 03-18-2024, 07:55 PM
Last Post: _Aka_
  GO can't fit end of the spline GameDeveloperek4123 3 13 03-04-2024, 11:06 AM
Last Post: _Aka_
  Keeping a fixed spline length jh092 3 16 02-21-2024, 06:25 AM
Last Post: Primrose44
  How could I get position in spline from "From" value in BuildRasterizedPath? Chanon 1 8 02-12-2024, 09:54 PM
Last Post: _Aka_

Forum Jump: