Official Lynda RTS tutorial review/Q&A.

Hello, I have a class on Lynda.com on how to create your own 3D Real Time Strategy game in Unity 5.

To anyone who is interested, has questions about it, or has any comments to share, please do so here.

1 Like

are you able to post to Pluralsight too? :slight_smile:

1 Like

I am going to check this out! Thanks for sharing the info about it!

1 Like

@tswalk saddly, I cannot post the same content on the pluralsight and lynda.com, Though I am planning on Udemy next.

Hi Dan,

Great tutorial! Joined Lynda just for it! How would you implement a drag box select and double click (select all similar units in view) for the units?

Warm regards,
Tony

1 Like

I would probably use a cube, setting one corner where I clicked initially, and another corner following the mouse. The cube would be a trigger, and transparent (like 80%).

The cube’s size would be something like Z = 10(make it designer editable), x = distance between x1/x2, y = distance between y1/y2. Place the cube at ((Point1 + Point2) / 2) (between the two mouse points)

Finally, selection would be every unit in the bounding box.

I would setup a reaction event to refresh this every 0.1-0.2 seconds, so I’m not spending too much of the cycles marking which characters are selected.

Another option would be to use a bordered empty UI image to mark with, and after translating screen to world coordinates, gather all the units with X and Y in the rect.

The second is probably the less expensive option, but the first would probably have some interesting visuals.

Thanks Dan,

Will give it a go!

Warm regards,
Tony

nice tutorials Dan but realy missed one thing it doesn’t have multiple unit selection with mouse drag which is one of main bone of RTS games since selecting one by one one unit is realy hard :confused:

1 Like

@Jenifer_Jane I agree. Their are a hundred extra things I would like to have added, but I had to make choices to keep the time down. I think that is the weakest part of playing the game right now, and the 2nd would be the lack of ability to click on the mini map to move the view.

I tried to give a starter for most of the sections, something to get you going, but I had to leave them minimal. Polishing the work could have easily tripled the time. Even if I did resolve those 2 things in the class, other things would have likely felt just as important.

However, perhaps I could post some extension video’s on my upcoming Unity/WebGL blog. Some things to clean it up a bit. I’m a bit busy and might not be able to get to it July/August.

There are good implementations of drag select on youtube. There is also this one which is a simple but effective implementation (my favorite kind): RTS Style Unit Selection in Unity 5 - Jeff Zimmer

K

1 Like

ok thnx

thnx will give it a try ^^

Very much appreciated! I like this method! Clean article too.

Hi, I’ve followed the tutorial and everything works up until the building placement. No matter where my ghost building is, it stays red. I even deleted my terrain and replaced it by an empty terrain with no other objects. I’ve checked for typos or forgotten things in the code, but all appears to be as in your tutorial so I don’t really know what’s wrong. I’ve tried with a unity cube and a custom mesh.
Any idea what could cause the issue?
Thanks

Sorry to hear you’re running into an issue. Its been a while since I’ve looked at it, but I have a couple ideas.

  1. The object is supposed to be high enough that it doesn’t overlap the ground. I.e. a cube starts from the center, so half of it would be colliding with the ground. You could be running into the same issue with a model.
  • Make sure your center point is at the bottom of the model. Or even instantiate it a little (just a little) higher than expected.
  1. When creating the video series, I ran into a bug that broke my code for several days while I pulled my hair out trying to figure out why it failed and worked before. Turned out, in the code that checks for over lap, I wasn’t excluding the transparent version of the object. I.e. I’m using a building as a cursor, and then checking to see if it overlapped with any other object in the scene. So every time it checked, it caught that it’s own model overlapped with itself.
  • Check to make sure your overlap testing code tests if your cursor building is the building it compares against. If it is, it should run a “continue;” in the loop to skip it. one tiny missing line breaks everything. :slight_smile:

I think I’m recalling that 1 would not be an issue. I think it took each vertice in the model and made sure that point didn’t collide with another object, but that it is a fraction higher than the ground for collision testing. Assuming I’m right in my recollection at the moment, then #2 is most likely the correct problem.

If you are still having trouble, I would put a debug point in the code. to check for it.

I know debugging where a 3D point intersects with others, can be difficult in VS, as it only shows you the problem in the code and you can’t visualize it at the same time. Here is a trick. Create a game object with some transparent object in it. Something to help pin point 3D space. Then create a class like this:
public class Debug3dPoint : MonoBehaviour
{
public static Vector3 At = Vector3.Zero;
public void Update()
{
transform.position = At;
}
}
// code might have a typo. I just entered it off the top of my head
The whole point is that this 1 test object will show up anywhere that you say Debug3dPoint.At = [target 3D position]; Once you have this object in your scene and enabled. In the code that checks for overlap, have it say Debug3DPoint.At = checkPosition; (or whatever the vector 3 variable name was it was checking).

When running the scene, you will see this constantly showing where in the scene it was failing. if you can’t see it, pause the scene (Ctrl/Cmd+Shift+P) and look for it through the hierarchy. (Or if it is succeeding, it will still show up, but only in the last place you tested.)

Since the overlap functionality returns a false as soon as it finds something, that test object will now point to the exact spot that is causing it to return false. :slight_smile:

Hey, thanks for the answer. The 3d debug trick will be pretty useful! My problem wasn’t actually code related (or I think). I noticed that I cleared the NavMesh so I tried to rebake it and the prefab became green ! So just me being a noob I guess :slight_smile:
That raises another question though which will probably be useful to others. The building placing depends on the NavMesh. My project is more of a city-builder (caesar more than simcity) but this tuto is still useful to me (especially the building placement since it is 50% of the game). My problem is that the terrain I use is not flat. Obviously, the player shouldn’t be able to build on mountains but since my terrain has small hills, most of the time, the prefab turns red. Is there a way to allow parts of the mesh to be under the terrain if most of it in over it?

I had designed a solution to this a while back. Where you want things to build on hills for instance. Here was the trick I used. When dragging the building around, check all the X/Z points to see what the highest terrain point is.


Then your model must have a “basement”. I.e. this can literally be a concrete texture block that is part of your building model. The highest point of the terrain is where your actual building starts. The lowest point on the terrain must not be shorter than your basement. The basement will be seen supporting it.

(You could also just place your building height at the highest terrain point, then place a cube underneath with the basement texture, stretched to fit any height. You could expand use the cubic units of space that block takes to increase the building cost, allowing you to build in steeper places, but making it more expensive. :slight_smile: )

Now if you have units exiting a building, then this doesn’t make as much sense. You’d have to add extra code to make sure the building has a valid exit point. I.e. tanks aren’t going to roll out and take a 20 foot plunge. :slight_smile:

It runs on the same principal of free placement.

Ok, thanks for taking the time. I’ll think about the basement idea, i’ll probably adapt it and use it :wink:

Hi Dan, great tutorial thus far but I am running into a slight issue that I believe may be related to the NavMesh. When new units are created in the command base, they stay locked inside the building and aren’t pushed out by the colliders.

The drones have sphere colliders and the base has a box collider, I’ve pretty much followed the tutorial to the letter up to Chapter 9, and there don’t appear to be any typos or bugs.

Any idea why this might not be working properly? Should I perhaps instantiate the newly created drones with an offset from the base?

EDIT: Nevermind, I refreshed the reference to the Drone unit prefab in CreateUnitAction.cs inside Unity and it started working properly.

Awesome! I’m glad that resolved itself! (I had a few suggestions in mind when reading it, but they were not the solution you found.)