Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Trying to create an RTS

Discussion in 'Scripting' started by Slayergnome, Sep 6, 2011.

  1. Slayergnome

    Slayergnome

    Joined:
    Sep 6, 2011
    Posts:
    4
    Hey,

    I really want to start the creation of an RTS so my question is 2 fold.

    First, I know unity is more centered around first person stuff so do you think that it is an appropriate engine or is there a better engine for making my game (I know there are some RTS specific engines but unity looks like it is more supported and easier to use)

    Secondly, I am having a hard time finding tutorials on the stuff I need. I.E. the camera scrolling when the mouse is near the edge of the screen(I actually did find this but it took a while), and more importantly selecting and manipulating multiple objects at the same time with the mouse. Can anyone give me a tutorial are a starting point for this?


    Thanks,
    Slayergnome :razz:
     
  2. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    Unity is not centered around any kind of game.

    You are not finding tutorials on those because it is rather specific. You are expected to already having a basic grasp on programming.

    Tutorials are not meant for helping you create a type of game, they are meant to introduce you to programming. They just happen to use subjects you are familiar with.
     
  3. KyleStaves

    KyleStaves

    Joined:
    Nov 4, 2009
    Posts:
    821
    I think you just need to break what you are trying to find down into smaller chunks. Instead of trying to find "move camera when mouse is near edge of screen in direction of mouse" - break that down into exactly what you need.

    1: How to detect mouse position
    --- How to translate this position into a normalized "area" of the screen (top/bottom/left/right/corners)

    2: How to move a game object

    Both of these individually are very well documented and easily found via google/the unity documents.

    For your next question, break that down into smaller bits.

    Q: How do you select game objects?
    A: There is no built-in way to handle this, but it's not really difficult either. You need three components really.
    1: A visual indication that a unity is selected
    2: An internal list of all selected units
    3: A method for selecting and de-selecting units.

    For 1, that's up to you. Personally I would probably have the "selected" graphic as a component of each unit that can be toggled on and off.
    For 2, that's just a simple management class (or a function of a larger class more likely) that can literally be as simple as a List<YourSelectionClass/Interface>.
    For 3, you can approach this multiple ways.

    First, you could use MonoBehaviors OnMouseDown function and have the unit handle it's own selection/deselection.
    http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.OnMouseDown.html

    Alternatively, and probably the better route, you can have a "selection" script which uses raycasting to find and select units. This approach would be more extensible (make it easier to add eventual marquee style selection instead of having to click each unit individually)/keep things cleaner.

    Manipulating the objects is significantly more difficult, as it almost certainly involves pathfinding. In a strategy game, you'll need well optimized pathfinding too. Honestly, with your likely level of programming knowledge this would be virtually impossible for you. Not only are you not yet capable of writing a pathfinding component yourself, but you also do not know the correct questions to ask to find the answers yet.

    A RTS game involves relatively complex A.I. programming, some of the most difficult programming you can do in Unity really. I'm not saying it's not impossible, but it will be very difficult and perhaps is not the best place to start. That said, 3.5 hopefully will have some built in pathfinding with Unity itself, so this portion of the project should potentially become significantly more approachable.

    For now, I really - really suggest working through some of the Unity tutorials that do not necessarily apply to what you want to do for your own project. They will still greatly aid you in learning the correct questions to ask to find your answers more efficiently.
     
  4. Afisicos

    Afisicos

    Joined:
    Nov 13, 2010
    Posts:
    326
    Very nice answer KyleStaves.

    I think the same but i'm so ambicious and I wanna too create a RTS game.
    I suggest you start with a game composed by 2 units (use cubes or spheres) and try to learn IA programming and all that Kyle said.
    Don't take care with textures, buildings, statistics, items, or creation of the units. Just try to make a pahtfinding, the camera moving, mouse controller and some GUI functions to show something.

    Good luck
     
  5. MarkusDavey

    MarkusDavey

    Joined:
    Jun 3, 2011
    Posts:
    258
    Me, having attempted an RTS, knows first hand that you'll be in for a LOT of work. The BEST thing you can do is draw a big assed flow chart for each aspect of your game. Eg

    Game starts > display main menu > if newgame clicked -> go to new game menu, etc etc.

    But do it in picture from. There's a few flowcharting tools out there. If you're doing a collaborative, you should invest in a http://www.lucidchart.com/ membership, or beg google to develop a like-minded concept for gDocs.
     
  6. Slayergnome

    Slayergnome

    Joined:
    Sep 6, 2011
    Posts:
    4
    Thanks for everyone's help. As for programming, I am not claiming to be an expert but I know a little bit, I have done some game programing in XNA but I am somewhat new to the whole scripting/connecting scripts to objects thing. Also I don't really want to get into to much details about how the game I am thinking about will work but it should be little more than what I asked selecting multiple units and manipulating them and I have already put together a design doc for it (I had a videogame programing class in college and this was my idea which was rejected).

    Also I do not expect raycasting (which I did take a OpenGl programing class in college and have some clue how to do) is something that comes naturally to most normal programmers Dman so it does not seem crazy to ask for some basic example scripts of other peoples use of ray casting.

    Finally, I want to point out that asking if there is a more appropriate engine (I.E. one with BUILT IN path finding) does not seem like a crazy question to me, you must remember this is the first time I have ever touched Unity and based on the fact there a default key scripted to a string called Fire I think it is safe to say that unity has more builtin functions for an FPS than an RTS (At least that is how it seems from the outside).

    Sorry to get a little defensive of my question, but thanks kyle I do appreciate the point in the right direction.
     
  7. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    Since when did I say raycasting should come naturally? My point was that after you know how to program, it's time to ditch the tutorials and read the scripting reference.

    I don't know of any other engine with pathfinding, but it's not too bad once you get the hang of it. I can upload a simple implementation using nodes when I get back to my computer if you like. It doesn't avoid other units, but it should give you a start.
     
  8. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,462
    Good pathfinding with an RTS can be quite a nightmare. There are many different ways and it can be a challenge to find an efficient solution. Lot's of info online.

    Unity can just as easily be used to create an RTS as it can an FPS.
     
  9. Slayergnome

    Slayergnome

    Joined:
    Sep 6, 2011
    Posts:
    4
    Ok, fair enough, that was bad wording on my part. I call example projects scripting references and everything minus the official documentation a tutorial. But yea I would appreciate that if you have it.
     
  10. Lioncirth

    Lioncirth

    Joined:
    Apr 7, 2009
    Posts:
    111
    If your happy to spend a little money, I believe there is a RTS kit at game prefabs.com that deals with camera and selecting units. Not sure if that is what your after
     
  11. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    Attached.

    For more information go to http://forum.unity3d.com/threads/93958-Anyone-familiar-with-A*-pathfinding-have-a-working-example-project-that-I-can-pull

    Or Google around for A* (the pathfinding algorithm).
     

    Attached Files:

    Last edited: Sep 6, 2011
  12. Slayergnome

    Slayergnome

    Joined:
    Sep 6, 2011
    Posts:
    4
    Umm, no thank you I think I can handle that. I am not trying to reinvint the wheel so I was thinking if someone had something already set up I could use that as a jumping point but I could do the move the camera thing in no time (when mouse is close to top of screen transform.position.x += scrollspeed or whatever) and even the selecting units is not sounding like to much of a challenge. Manipulation is what I think is going to cause the problem.

    But thanks for letting me know it exist :D