- Home /
Endless racer - positioning of track segments
I’m creating an endless racing game. The track is generated by joining together track segments end-to-end, from a pool of prefabs ( straight, corners, slopes, banks etc ).
Each track segment has a child node (start and end) at either end to use as a reference for joining the pieces together. These are oriented so that their blue (Z) axis is pointing in the direction of the track.
Question 1 : When placing a new segment, how do I correctly calculate the position and rotation such that the start of the new segment is perfectly aligned with the end of the last placed segment? This code seems to work ok until the track gets banked:
newSegment.transform.eulerAngles = mLastPlacedSegment.EndRotation - newSegment.StartRotation;
newSegment.transform.position = mLastPlacedSegment.EndPosition - newSegment.StartPosition;
Question 2 : How can I check how much the track is sloped and banked at the position of the end point on the last placed segment? ( I need to know by how much the end point is rotated on it's X and Z axes separately, but in world space )