Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

2D RTS Click for Grid Movement

Discussion in 'Scripting' started by GnomenxD, Oct 6, 2014.

  1. GnomenxD

    GnomenxD

    Joined:
    Oct 6, 2014
    Posts:
    2
    Hello, my name is Philip and I'm currently developing a 2D RTS game, unfortunately I'm missing out one of the most important components for a RTS game, the basic movement of all units. At the movement for the game mechanics there are a building system, which creates a "Ghost" of a buildings when a button is pressed. The building ghost will snap as close to the mouse as possible, but will always be snapped to a grid.

    I've tried to work on this movement for a quite long time now and is now to seek help from others.

    My dream for the movement:

    • Units shall be able to receive a desired location of the closest grid near the mouse when pressed.
    • Units will always be snapped to the grid, but shall be able to make smooth movements between them.
    • Units are able to move diagonally on the grid.
    • Units will automatically find to shortest route for the desired location.
    • Units are possible to move around buildings and other environments.
    • Units are always able to change route, every time the command is given.
    I'll be very pleased with anything possible to help.
    Many Thanks
     
  2. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    A* does everything you need. If you don't want to implement it yourself then I would recommend Aron Granberg's package.
     
  3. GnomenxD

    GnomenxD

    Joined:
    Oct 6, 2014
    Posts:
    2
    Thanks for your quick reply, I've now tried to play around with the A* path-finding. It's a really great system and I'll guess it could work really well. Unfortunately, it can be it's just me who isn't well explained enough with this system of use, but of what I've seen, tried and read, I don't totally have the opportunities for what I'm seeking. But as I've said, it can also just be because of the lag of skills I got for a new system like this.
    • It doesn't totally snap perfectly aligned with the grid, neither when positioned nor moving.
    • Sometimes if the units ain't able to reach their position, they try to bump against each other.
    • They do not move to the totally end of the path which is given.
    • I'll have to implant a totally new building system. (It might not be the hardest, but it might have to be done)
    I do assume myself that this is, as said because I do not know of the totally customization of this system. But it's unfortunately what I've gotten for now. I do not know if you nor anyone are able to help me out or guide me a little in this situation.

    Regards
     
  4. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    A* is just going to give you a path from one place to another - how you move along that path, handle instances where an agent can't get to its destination, or prevent agents from running into each other is ultimately up to you and should be customized for your specific case. It sounds like you also need to research steering behaviors which will allow your agents to move along your A* paths.