Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Aligning objects from points on spline
#1
Hi, I've decided to change how I move objects on a spline by using two points instead of one so I can increase the precision of the edges of the objects(so they align better with the objects in front/behind of them). I thought of mimicking your train example, but slightly different.

I have the object setup as a prefab with all meshes and stuff as children. My idea is to also create two fixed points, one in front and rear, also as children to the prefab. Then align them to the spline and then place the whole prefab in the center of those two points.
Now the problem. Precision is very important here so I need that once they align to the spline, the world distance that the two points have to each other should be exactly the same as they had to each other in the prefab, before aligning. Placing the first point is no problem, but I have no idea how to get the point on a spline that is X world units, in a straight line, from the first point.

I use Playmaker so I don't need any code, just how to calculate this.

Or, if you have a better way to do this, I would like that instead.
Reply
#2
Hi
There might be some mathematical formula that gives you, given a spline, a distance D and a point A on the spline, gives you a point B that is at linear distance of D from A. If such formula exists, I am not aware of it. If you need crazy precision, that would be the path to explore, but I guess that you don't need such level of precision.

The easier solution is to go through all the cache points of the spline (yourspline.GetApproximation), and test their linear distance with the point A, and take the point which distance is closer to D.
You can improve precision by instead of taking that point, to search linearly between two points B1 and B2, B1 being the one with a distance directly under D, and B2 being the point with a distance directly above D.
You can improve performance by searching just the cache point between two tf values, tf1 and tf2. tf1 would be the tf of point A, and tf2 would be the tf of the point that has a non-linear distance of D on the spline from point A.

Sorry, I don't have any simpler solution (besides the method used in the train example scenes)
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
If you don't know how to calculate that there's no way I will ever figure it out with my math unskills. Idea Hmm, maybe this is a good feature request for the future. An action that places an object at a fixed, linear distance from an other object on the spline. Sounds good? Big Grin

Anyway, to get this approximation info should I check the use cache button in get info action? Or is it something else or can you only do it by code?

I had a little trouble follow your example, but if you use that method wouldn't the result change a bit every frame? I don't want precision just for the sake of it, but to keep the two anchors at the same position from each other. If the distance changes every frame it will make the movement jittery and that's what I try to avoid.

Maybe this is what you said and I didn't get it, but how about this idea? On the frame the object spawn you get a center point from the object and align it to the spline as normal. Then from that position you get the closest point on the spline for each of the anchors and align them to the spline. Now every following frames you move these two points a fixed distance on the spline just as you would move a normal setup and then align the parent to the point in the center of them.
Would this keep them a fixed distance from each other, precise enough that the object doesn't jitter? Or am I completely off here?
Reply
#4
(02-19-2021, 07:52 PM)Lupp_ Wrote: If you don't know how to calculate that there's no way I will ever figure it out with my math unskills. Idea Hmm, maybe this is a good feature request for the future. An action that places an object at a fixed, linear distance from an other object on the spline. Sounds good? Big Grin
Sounds good Big Grin I noted the feature request, but it is not on the top of the priority list.

(02-19-2021, 07:52 PM)Lupp_ Wrote: Anyway, to get this approximation info should I check the use cache button in get info action? Or is it something else or can you only do it by code?
GetApproximation is a public method of CurvySpline, so like all other API methods, you should be able to call it through Playmaker or Bolt.
   
I have no idea about how easy or feasable to implement the whole logic I described, I have no experience using for loops and whatnot via PlayMaker

(02-19-2021, 07:52 PM)Lupp_ Wrote: I had a little trouble follow your example, but if you use that method wouldn't the result change a bit every frame? I don't want precision just for the sake of it, but to keep the two anchors at the same position from each other. If the distance changes every frame it will make the movement jittery and that's what I try to avoid.
There are no reasons for the result to change. If you go back to my example, all the input data is:
the spline, the distance D and the point A. As long as none of those change, the result should not change.

(02-19-2021, 07:52 PM)Lupp_ Wrote: Maybe this is what you said and I didn't get it, but how about this idea? On the frame the object spawn you get a center point from the object and align it to the spline as normal. Then from that position you get the closest point on the spline for each of the anchors and align them to the spline. Now every following frames you move these two points a fixed distance on the spline just as you would move a normal setup and then align the parent to the point in the center of them.
Would this keep them a fixed distance from each other, precise enough that the object doesn't jitter? Or am I completely off here?
This is basically the idea of the train example scene as far as I understand. I think it is a simple solution that gives satisfying results, and I am all with simplicity. Keep in mind that through hours or running, errors in floating points computation (in simpler terms, inherent errors related to float operations) will accumulate, so checking that both anchors keep a constant distance between them is important, and correcting that when necessary. This is what is done in the train example scene.
Approximating a linear distance to a non linear distance is a simplification that is not exact in some cases, but if it gives good enough results, then why not
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#5
Very good, thanks a lot for the explanation. I'm gonna see what I can do during the next days.
Reply
#6
Well, this took longer then expected, but now I've remade the movement to use 2 points instead of 1. The result is very good. Even with sharp curves it looks like the terrain is bending even if it's not. Very happy.
Reply
#7
Glad to read that
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
  snap to the curve created by the curvy splines segment points ShiroeYamamoto 1 2 Yesterday, 10:23 PM
Last Post: _Aka_
  Curvy Line Renderer for UI Spline? gekido 1 1 Yesterday, 10:12 PM
Last Post: _Aka_
  Get position of all control points for a spline gekido 1 2 Yesterday, 10:08 PM
Last Post: _Aka_
Bug Changing spline connection in inspector causes splines to revert to defaults lacota 3 6 03-18-2024, 07:55 PM
Last Post: _Aka_

Forum Jump: