playMaker

Author Topic: [SOLVED]Creating a Room-Brush system with Playmaker? (SNAPPING)  (Read 1161 times)

Bipolar

  • Playmaker Newbie
  • *
  • Posts: 41
    • View Profile
[SOLVED]Creating a Room-Brush system with Playmaker? (SNAPPING)
« on: February 11, 2018, 08:44:44 AM »
Hi!

I would know if it is possible creating (err... I don't know how call this build system in english) a Brush to Draw different types of rooms. The same as Evil Genius:

https://www.youtube.com/watch?v=-345V3ciDBk

They should snap like a grid.
Which actions I need to made my custom system?

I tried to find something on the asset store, but I don't know the specific name of this build mode. Moreover It's top down only when you are in customize mode: the game I would to exercise with, is fps and top down only when you want to build something.

Some tips?


« Last Edit: February 15, 2018, 03:40:47 PM by Bipolar »

Doh

  • Junior Playmaker
  • **
  • Posts: 88
    • View Profile
Re: Creating a Room-Brush system with Playmaker?
« Reply #1 on: February 11, 2018, 09:17:32 AM »
This question is extremely broad. Though I can suggest something that may start you off in a viable direction.

I'd start by using "get mouse button down" in one state, then in the next state I'd grab the position of the cursor (one of the "mouse pick" actions could do it) and round each vector to a whole number (you may want to use one of the vector XYZ actions that allow you to break up a vector into a series of floats, then use "float round to nearest" on each value). I'd then use "get mouse button up" and once again in the following state grab the position of the cursor and round each vector again.

You've then got 2 opposing corners of a rectangle to lay out your rooms. From there you'll need to work out how you'll place your rooms within that rectangle.

As I said though there are many ways to accomplish this effect, this is one way that is fairly straight forward in Playmaker.

Bipolar

  • Playmaker Newbie
  • *
  • Posts: 41
    • View Profile
Re: Creating a Room-Brush system with Playmaker?
« Reply #2 on: February 11, 2018, 09:25:21 AM »
This question is extremely broad. Though I can suggest something that may start you off in a viable direction.

I'd start by using "get mouse button down" in one state, then in the next state I'd grab the position of the cursor (one of the "mouse pick" actions could do it) and round each vector to a whole number (you may want to use one of the vector XYZ actions that allow you to break up a vector into a series of floats, then use "float round to nearest" on each value). I'd then use "get mouse button up" and once again in the following state grab the position of the cursor and round each vector again.

You've then got 2 opposing corners of a rectangle to lay out your rooms. From there you'll need to work out how you'll place your rooms within that rectangle.

As I said though there are many ways to accomplish this effect, this is one way that is fairly straight forward in Playmaker.

Mmh... And to adding the 3D subtractive/boolean effect in the stone(for example?). Anyway, I'm going to try, I'll let you know. Thanks!
« Last Edit: February 11, 2018, 09:30:37 AM by Bipolar »

Doh

  • Junior Playmaker
  • **
  • Posts: 88
    • View Profile
Re: Creating a Room-Brush system with Playmaker?
« Reply #3 on: February 11, 2018, 10:15:09 AM »
The cut away effect in the video you provided could be done many ways too depending on the complexity of your use.

You could have a mesh object that represents one grid square of stone and simply disable it when something is built in its place, though this could impact your performance if the landscape is large, I wouldn't recommend that method unless you're working small scale.

There is a method of masking that would probably be more efficient. It involves render queues and depth masks. It is explained very well in this video https://www.youtube.com/watch?v=cHhxs12ZfSQ in the description there is a link to download his project, you could use that to get his shaders if you wish. So if you imagine you could use the shader he uses in his green material for the stone and the shader used in his grey material for your rooms, then have a plane placed just above ground level with his depth mask shader. If you watch the video you'll understand how he does it.

Bipolar

  • Playmaker Newbie
  • *
  • Posts: 41
    • View Profile
Re: Creating a Room-Brush system with Playmaker?
« Reply #4 on: February 11, 2018, 10:47:42 AM »
Really helpful! Thanks.
« Last Edit: February 11, 2018, 10:58:27 AM by Bipolar »

Doh

  • Junior Playmaker
  • **
  • Posts: 88
    • View Profile
Re: Creating a Room-Brush system with Playmaker?
« Reply #5 on: February 11, 2018, 11:39:11 AM »
I hope it goes well!  :)

Bipolar

  • Playmaker Newbie
  • *
  • Posts: 41
    • View Profile
Re: Creating a Room-Brush system with Playmaker?
« Reply #6 on: February 11, 2018, 11:50:59 AM »
I'm back.
Im sorry to spam questions here, is there some tutorial for it?
I've actually problems to create an object based on the rounded variables.
There's a portion of map which is not editable.
I don't know what's better: creating a clone of the same object reapeated for each snapped ordx and ordy or just scale it on the previous ones.

Moreover the dragged area should work like an autotile.

(Hope I'm undestandable)

« Last Edit: February 11, 2018, 12:12:04 PM by Bipolar »

Doh

  • Junior Playmaker
  • **
  • Posts: 88
    • View Profile
Re: Creating a Room-Brush system with Playmaker?
« Reply #7 on: February 11, 2018, 01:28:51 PM »
No bother, I think I understand you pretty well.

I've never seen a tutorial on this personally but I have built similar dungeon-like pieces.

Once again there are many ways to accomplish the different components involved. You're going to have a lot of trial and error attempting to create this.

The most straight forward way I can think of would be to create modular building blocks that your code can pick from when building the rooms. So you could make a corner piece, a wall piece and a door piece (each of these should be 1 meter wide for simplicity), make sure that they all slot together seamlessly in your modelling program of choice (set their pivot points in a position that is universally shared across each piece). Once in Unity use these in your room setup script (doors you would likely make the player place manually after a room is generated).

If the modular pieces don't suit you then yes you can just scale wall pieces and either scale the UVs of each mesh as well or use a tri-planar shader. I'd use a mixture if it were me, I'd have modular wall pieces and a scaled floor plane.

If you have fairly constrained room building dimensions, lets say a room can be a minimum of 2m x 2m and a maximum of 6m x 6m then you could even build prefabs of all possible room sizes in advance. Though as you want to paint them I think working on a modular wall system would be best.

Sorry if this is a jumble of information. Let me know if you'd like me to attempt to elaborate on a particular part.

Bipolar

  • Playmaker Newbie
  • *
  • Posts: 41
    • View Profile
Re: Creating a Room-Brush system with Playmaker?
« Reply #8 on: February 11, 2018, 01:43:24 PM »
I just don't know which actions I need to build.
The snap now works, but which action I need to Draw?

I 've understood playmaker's logic, just need more actions knowledge and practice with them. :)

Anyway only ambient is 3D, the other stuff is only 2D as you can see here:
https://www.youtube.com/watch?v=A1UhtLuLMGc

Doh

  • Junior Playmaker
  • **
  • Posts: 88
    • View Profile
Re: Creating a Room-Brush system with Playmaker?
« Reply #9 on: February 11, 2018, 03:01:23 PM »
So what you need to do it set the position of a series of game objects along the sides of the rectangle, with the appropriate rotation too.

You'll need to use the two vectors you've rounded to work out how long each side of the rectangle is. I'd probably find out the difference between the two X positions and the difference between the two Z positions (use whatever you find easiest from the "math" category of actions). You should now know the dimensions of the rectangle. With the dimensions you can create an array for the X length and another for the Z length, each array would store the positions where the meshes would need to be placed on that edge of the rectangle. Once you've got an array of all the points on a side you can loop through those using the "array get next" action and apply the position to the next piece using "set position".

At this point if you haven't used arrays yet you will need to. I'd recommend going through some tutorials on that. The most suitable way you populate the arrays according to the dimensions of the rectangle are beyond my guessing at this point.

Once you've managed to use these hints to create a working system of your own you should look into pooling. I'd recommend PoolManager as there are Playmaker actions for it.

https://assetstore.unity.com/packages/3d/characters/poolmanager-1010

I use it to pull meshes I require from a group of pre-existing meshes waiting to be used, in your case that would be your wall pieces among other things. It avoids creating and destroying game objects at runtime.

Good luck with all that, it will take some doing to get the array stuff going if you're new to the concept but it'll pay for itself many times over in the future.
« Last Edit: February 11, 2018, 03:03:28 PM by Doh »

Bipolar

  • Playmaker Newbie
  • *
  • Posts: 41
    • View Profile
Re: Creating a Room-Brush system with Playmaker?
« Reply #10 on: February 13, 2018, 08:11:04 AM »
Anyway I should explain me better.

The game map is not big: the buildable area is only 1/9 of the map and it's in the center zone of the little city.

The other part of the city is a pre-edited in a 3D program.

So ONLY the center is buidable (it's an empty terrain), Moreover is grid-snap based, so it's not possible place where you want, as I saied above.

the system is similiar to this https://assetstore.unity.com/packages/templates/systems/ubuild-in-game-modular-building-system-75709
but with cost in $ of each part of the structure to build.

I prefer don't use stuff from asset store, the reason is I am afraid they cannot be controlled completely by Playmaker (or it's possible?).





Doh

  • Junior Playmaker
  • **
  • Posts: 88
    • View Profile
Re: Creating a Room-Brush system with Playmaker?
« Reply #11 on: February 13, 2018, 10:07:10 AM »
You can work with scripts to some extent, check out the "ScriptControl" category in your action list.

Back to doing it all in Playmaker though, as you've got a very specific building location with a finite grid area I'd consider getting creative with how you lay down sections.

I've attached an image to try to illustrate how I'd begin approaching this.

I'd begin by creating an empty game object (Foundation Marker) at the center of each grid square and another empty game object (Edge Marker) on each edge within the grid. I'd then create two FSM templates in Playmaker, one called "Foundation Data" (add an FSM with this template to each Foundation Marker) and another "Edge Data" (add an FSM with this template to each Edge Marker), inside these FSMs I'd create variables like a bool called "inUse", and maybe a string (objectType) for things like "wall" or "door" and various others as required to contain information on the building that has or hasn't been done there. I'd create a layer called something like "Edges", I'd then add all of the Edge Markers to this layer. I'd then add a collider to each "Edge" game object so that the raycasts in the next part have something to hit. I'd also create a global array (called foundationMarkerList) with all of the Foundation Markers added to it.

In the image you can see the cursor is hovering over a grid square, the "Snap Position" has been moved to the center of that square. From the snap object you can get all of the information you may need using two techniques, firstly I'd use the action "array get closest game object" and check the "foundationMarkerList" array, the result should be the Foundation Marker under the snap position, I'd then raycast out 4 directions (-x,+x,-z and +z) to find the adjacent Edge Markers (limit the raycasts to the Edge Markers layer using the layer mask on the action).

You now have the game object for your current foundation piece and it's adjacent potential wall parts, you can now access the variables you set up in the two templates made earlier by using actions like "get FSM variables". With the data you query you can enable/disable GUI elements etc to let the player know what options they have in that particular grid position. I'd be tempted to make it so they have to click on the square to lock the Snap Position in place and bring up a menu with options from there. When they choose something make sure to set the relevant variables ("inUse" = true, "objectType" = stoneFloor etc) on the marker object it's related to and the whole system should come together nicely.

Final note: make sure to disable collisions between the "Edge Markers" layer and things that shouldn't collide with it (player controller, enemies etc).

I hope this suggestion holds some use for you!
« Last Edit: February 13, 2018, 10:15:53 AM by Doh »

Bipolar

  • Playmaker Newbie
  • *
  • Posts: 41
    • View Profile
Re: Creating a Room-Brush system with Playmaker?
« Reply #12 on: February 13, 2018, 02:43:24 PM »
I'm making this right now.
I 've created a green area of 300x300 and a tile of 10x10 units.
I renamed this FoundationMarker and I set as child of it 4 empty GO for each edge.

Right? Just one gameobject with inside 4 child?

Or You mean creating 900 FoundationMarker with their EdgeMarker?
« Last Edit: February 13, 2018, 02:46:39 PM by Bipolar »

Doh

  • Junior Playmaker
  • **
  • Posts: 88
    • View Profile
Re: Creating a Room-Brush system with Playmaker?
« Reply #13 on: February 14, 2018, 04:56:28 AM »
Sorry could you clarify the size of the area you're going to build on? 300x300 is larger than I thought. I'd be hesitant of making enough colliders to cover that, there are more efficient ways to find the adjacent markers, the ways I am aware of will just take longer to set up.

Could explain what the green area is and whether it is 300x300 meters?

Could you explain also what a tile of 10x10 does/is?

Is the building mode only active for short isolated periods?

In my solution I was expecting each object to be it's own game object or at most siblings, not children, you'd have neighboring Edge Markers overlapping in that case.

Doh

  • Junior Playmaker
  • **
  • Posts: 88
    • View Profile
Re: Creating a Room-Brush system with Playmaker?
« Reply #14 on: February 14, 2018, 05:09:59 AM »
Actually, just had a ponder, your child idea might work far better. Try making it so the snap marker has a trigger in place of the floor and one for each edge. Then just check for building objects already in their places. This way you can avoid having the surplus of game objects. If you want to extend this to extra floors you'll have to add in checks for lower levels and another set of triggers for each extra floor. Though I'd keep it as simple as possible.