I’m mostly new to unity but not to the coding stuff itself. So i try to avoid big written lines here and appended a picture to draw my problem. I need a good solution to do that what can be seen on the image attached. I won’t do that with predefined splines or calculated paths. I need a hint how i can do that properly on runtime. The trains are controlled by the player, able to modify on runtime (couple, uncouple etc pp). The tracks/lines/paths are pre stored in a path table (array off waypoints as a network representation of combined paths (thats the thinking how to do that, not really done by now)). I just want to know whats the best way for that movement problem. I mind that it can only done by huge maths but i’m not that familiar with the maths on vector3’s or something. Were better i can to it by physX but that is not an option for mobile devices.
So i’m very appreciated if somone can explain me a method how to do it. I do not need complete scripts. Just some hints and math examples that i can “read”.
Break bezier spline into segments.
First snapped pivot represents in values: segment index and segment parameter [0.0; 1.0).
Second snapped pivot can be found by intersection circle (radius = distance between wheels) and some segment.
And so on…
Hm, i don’t get it. And i think that method only works with PhysX. On a non physical GO i can’t move two transform positions. With physics i can put on there two joined other GOs (bogies) and move them seperatly to move the main body, or move the body and clamp the bogies to the curve. But there is only one pivot on the parent GO without physics, the center/mesh pivot. So i think i have to calculate an offset from that pivot relative to the curve and rotation to move it virtually on these two points? I tried to move two childs but then the body doesn’t move with them. It seems very complicated to calculate this, especially on non uniform curves like cubic beziers or clothoids.
Just put 2 objects on the spline, seperated by the desired train length, moving at the same speed.
Have the pivot of the train at one of the objects, and have the train lookat the other one