Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Imagine a (3D) game like Railroad Tycoon 3. Player selects a rail track, clicks LMB and drags the mouse to the end position. During this drag, the rail track model scales and adopts to the landscape, so user sees the resulting track in dynamic.

The question: how this can be done? A brief idea/links/sketches will be enough. I just don't know how to start (I'm novice game developer). If it is matter, I use Unity as a game engine.

Thanks in advance.

share|improve this question
    
Tiling is usually the way to go. If you want something more complex (like allowing players to adjust the track down to the millimeter) then you are going to need to edit the models a little in your code. –  Benjamin Danger Johnson Mar 12 '13 at 18:58
    
Is the track that you are going to lay down limited to 90 degree increments for the angle or is it any angle? But even assuming only 90 degree rotations in order to use tiling you would have to ensure that the track segments line up with the edges of the underlying landscape mesh which means that the landscape mesh must have a density that is the same or a multiple of the track tile size. If you dont do that then the track will cut through or hover above the landscape. –  RobCurr Mar 12 '13 at 20:00
add comment

1 Answer

up vote 1 down vote accepted

As RobCurr states, simplest way to do this is to make sure the landscape mesh "matches" the track tile size, so that you don't get tracks that jutt above a hill or go through a suddenly ending slope.

What you can do in Unity is make a script that tells you the point on the landscape where the mouse cursors "is". I say "is" because obviouslly a 2d moving mouse cursor doesn't really intersect a 3d landscape. What you actually wanna do is create a ray cast from the camera, through the cursor and onto the landscape, and use the point where that ray goes through the landscape as the point where the mouse cursor "is" on the landscape.

Look up Raycast and this post here

Then you need to script up the behaviour of the track tile when the user drags his mouse "across" the landscape: how the track tile needs to be rotated, should it be straight or curved (if the player changes direction after already laying down some tracks), etc. Make sure you have a good grasp of prefabs and how to instantiate them for this part.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.