playMaker

Author Topic: RTS building placement how?  (Read 13131 times)

PlatinumPlayer

  • Playmaker Newbie
  • *
  • Posts: 26
RTS building placement how?
« on: July 24, 2012, 12:24:13 PM »
I'm no programmer so I'm at a loss of how to figure out going about making a placement grid for buildings/objects that need certain conditions to be spawned in a region. I saw a very good example of grid snapped object placement demonstrated in Castle Story and would like to use the same technique for a project of mine (castle story demo vid here:
I know they don't use playmaker, so my question is if it's possible to mimic this kind of grid snapping object building behavior with playmaker and if so where should I start? Logically I understand how it should work, I simply don't know how to go about building it or if playmaker has the built in actions to allow it.

Any input would be helpful!

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: RTS building placement how?
« Reply #1 on: July 24, 2012, 12:48:58 PM »
One way to do it would be to create a floating version of the block at the point of your raycast that follows the mouse around, then listen for mouse input to place the object, on mouse input scan collider of the floating block for triggers that are listed as failed placement conditions and return with either a fail or pass event and either create the object(and cleanup the floater) or return to the floater and listen for mouse input.

This kind of thing usually doesn't pan out until you jump in and get your hands dirty. Finding out if your method idea works and going from there.
« Last Edit: July 24, 2012, 12:51:06 PM by Lane »
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

PlatinumPlayer

  • Playmaker Newbie
  • *
  • Posts: 26
Re: RTS building placement how?
« Reply #2 on: July 24, 2012, 02:30:07 PM »
I guess i need the starting point, how do i make a grid that the mouse and the 'floating object' snaps to. Thats my biggest question, as for the rules of placement i can brainstorm all that, my issue is mimicking the grid like placement. How do i make it so objects have a footprint of 2x2 unity's, and the mouse snaps to the vertex of the grid lines. The image bellow shows what I'm trying to achieve (click to enlarge).

PlatinumPlayer

  • Playmaker Newbie
  • *
  • Posts: 26
Re: RTS building placement how?
« Reply #3 on: July 24, 2012, 07:46:14 PM »
Well I managed to make a test project to demonstrate a very simple grid snapping system, but I think it can be done better. I am attaching the package here so others can test it and hopefully suggest improvements. My next step is to add larger foot prints 2x2, 3x3, 5x5, etc, and figure out the best method of detecting a valid location. The current methods only good for 1x1 blocks.

NOTE: it seems my global variables did not export with the package. Please use the Playmaker menu Playmaker > Tools > Import Globals to add the globals to the project before playing.

Here is a basic rundown:

RTS Controller (1 FSM)

FSM: Mouse Tracker

This FSM tracks the mouse position and saves it as a vector3.
-finds the mouse pointers coordinates in the world.
-saves each vector to a float (Mouse X, Y, Z)
-converts each float to a INT to round it to a single digit (stores as: Mouse X INT, Y, Z)
-converts each INT back to a float (Pos X, Y, Z)
-stores the new floats to a global vector3 (Rounded Mouse Pos)

1x1 Block (1 FSM)

FSM: Can't Build On Me

This is a basic block in the world and it tells the spawned it can't build on it.
-when mouse is over it sets a global bool (Invalid Build Site) letting the spawner know it cant build
-when mouse leaves, it tells the spawer its okay now.

1x1 Block Spawner (2 FSM)

FSM: Follow Mouse

This state machine makes the spawned object follow the mouse courser and sets object material to represent state.
-sets Good Block material to indicate a valid spawn/build location
-constantly follows mouse using global vector three. The rounded vector numbers forces the spawned to snap to a grid made of 1x1 unit coordinates.
-waits for bool (Invalid Build Site) to be changed
-if bool is true meaning it's an invalid site the spawner stops following mouse and sets Blocked Block texture and waits for the bool to change again before acting.
-if bool changes and is false it returns to following the mouse cursor and again sets Good Block material.

FSM: Click and Create

This FSM waits for the player so it can spawn an object at the current location.
-waits for mouse click
-checks bool (Invalid Build Site) to see if it can build
-if invalid sets the Bad Block material letting the player know they were attempting an illegal action, returns to waiting for a mouse click.
-If a valid location spawner creates a 1x1 block bellow it.
« Last Edit: July 24, 2012, 08:26:15 PM by PlatinumPlayer »

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: RTS building placement how?
« Reply #4 on: July 25, 2012, 07:31:11 AM »
I havent had a chance to open your file up yet but I found this on the unity forums

http://forum.unity3d.com/threads/138355-Tile-Based-Map-amp-Nav
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Boom7Games

  • Playmaker Newbie
  • *
  • Posts: 9
Re: RTS building placement how?
« Reply #5 on: August 07, 2014, 05:36:47 PM »
Tried the import global variables tool but it still isn't working. Do you have any developments in this solution?

I appreciate it

bizilux

  • Full Member
  • ***
  • Posts: 171
Re: RTS building placement how?
« Reply #6 on: August 09, 2014, 10:56:07 AM »
interesting project, and i wish to offer my help with this, since i have been planning on making something like this for a long time, i just never got around to doing it (since it is not so simple obviously)

you have skype? you can add me and maybe we can brainstorm a bit and solve problems together, and if we cant find solution, we post it here. my username: bizilux

anyways i have Rotorz tile system, https://www.assetstore.unity3d.com/en/#!/content/3344
and i wanted to make this grid snapping with it, i think its very suitable for it, but like i said, i just never got around to doing it.

i do not have this one: grid framework https://www.assetstore.unity3d.com/en/#!/content/4004
but did you check it out? im reading that it works with playmaker, and maybe this is what we need for the sake of cutting corners?

although ofcourse its best to develop everything on ur own, to have total control, it just takes a bit more time.
« Last Edit: August 09, 2014, 11:02:27 AM by bizilux »