- Home /
Question is off-topic or not relevant
Paths / Waypoints
I am making a game that requires a car to follow a PRECISE track. I will start by making a world editor/maker in which I will create every level. The road will be split into pieces that can be built together to make a full road. So how to assign to each block a path to follow? PS: Each parts will have two parallel roads, and the car needs to travel in curves also. So how is this possible? can anyone point me to any resources?
In short is it possible to make a Prefab with a path assigned to it that can be combined with other prefabs to make 1 whole path? And what is that resource?
You can't ask to model your solution. You need to simple get in to the code and make it work.
He's asking for help solving an actual problem that he has and doesn't know how to do. That's exactly what this site is for. I for one would also be interested as to how this can be done in unity.
Thanks tbkn :) I have posted my approach that I have thought of in case anyone has another approach please do tell me :)
Ok... for me, it get into item A) of http://answers.unity3d.com/page/newuser.html
But I will love to see your answer @tbkn. Give it a try :P
I didn't ask for you to write any code :) $$anonymous$$y question was a logic question. What was the approach to do so :)
Answer by Tomer-Barkan · Oct 09, 2013 at 01:20 PM
Here's an idea, but it is a bit limiting:
You can pre-create several road "tiles", say for instance vertical road, horizontal road, and the 4 curves (bot/right, bot/left, top/right, top/left). Then for each one of the tiles, you'd define the location of the car in relation to the entry point for that tile. For example, a straight line would have the following function:
(x, y)(d) = (d, 0.5)
As in, the X coordinates equals D, which is the distance travelled from the leftmost point of the tile, while the Y coordinates are a constant 0.5. You can define the function as a script:
public Vector2 GetPositionInTile(distance) {
return new Vector2(distance, 0.5f);
}
Then as the car is travelling the road, you calculate the distance as a function of the car's speed and time, and then depending on the tile that the car is in, you calculate X and Y using the tile's function, and move the car to the correct position every frame.
Well I am splitting the game into a World Creator and the actual game. So I think it is better that the Builder uses this logic to combine the whole paths into one that way there is less computing time in the actual Game. But still thanks for your answer :D
Answer by Sisso · Oct 09, 2013 at 12:42 PM
So how is this possible? can anyone point me to any resources?
Yes, almost everything is possible and have a infinite way to do. Here is a good starting resource:
http://docs.unity3d.com/Documentation/Manual/Scripting42.html
Answer by Blink123123 · Oct 09, 2013 at 01:11 PM
I have found a solution to use iTween script located here: http://pixelplacement.com/2010/12/03/visual-editor-for-itween-motion-paths/ Now I am trying to figure out how to make a grid based terrain to add these paths dynamically. The best approach in my opinion is that every part has a script that indicates the path's behavior on it (starts on X relative to the cube and so on). Then when the whole terrain is created the code should create a whole new complete path according the the combination. I answered my own question I guess :P