playMaker

Author Topic: Array to detect if object is covering multiple positions?  (Read 3012 times)

4ppleseed

  • Full Member
  • ***
  • Posts: 226
Array to detect if object is covering multiple positions?
« on: March 26, 2016, 07:13:09 AM »
Hi all,
I'm using 1.8 and the array actions. Lets say there is a 4x4 grid and I have an object  (in red) that is a 2x2x2 cube like so...



I place the object in the top left hand corner of the grid. I would like to use an array to check if the object is covering the positions A1, A2, B1 and B2 separately. So if I moved the red object over to the right by 1 I could now detect it was over A2, A3, B2 and B3. So one object, multiple points in the array.

I've set up a global array for each of the grid places but can't work out how to check if the object is covering four different places at the same time as the game object only has one actual position.

Any ideas?
Thanks

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Array to detect if object is covering multiple positions?
« Reply #1 on: March 30, 2016, 06:35:15 AM »
Hi,

ok, your array will work with indexes so let's assume the following:

index : Id
0         A1
1         A2
2         A3
3         A4
4         B1
5         B2
6         B3
7         B4
... etc

and now you will create a global array of bools, where if let's say index 5 is true, that means B2 is red

does that make sense? what your board need to do is to raise and lower boolean values in that array depending on where the user click.

now, to check your situation you need to verify that index 0,1,4 and 5 are true, and that no other are false.

to do this in a clever way, you will have an fsm with an array of ints, representing the grid indexes to check for a valid pattern, in our case:

{0,1,4,5}

and your fsm will loop trough all indexes, and check if the current index is found within your pattern array, and if it is, it must be true, else it must be false.

during that loop, if a index is not of the expected value, you fail the pattern, else when the loop as ended all all indexes matched that pattern, you can assume you have exactly that pattern on the board.

Does that sound ok? the great thing about the pattern array, is that you can now define a lot of different patterns and check them with the same routine!

Bye,

 Jean

4ppleseed

  • Full Member
  • ***
  • Posts: 226
Re: Array to detect if object is covering multiple positions?
« Reply #2 on: April 01, 2016, 07:18:52 PM »
Hi Jean,
I understand the part about the arrays.

The problem I have is the object's position is in one place - where the green cross is. But I want to detect is my one object is covering A1, A2, B1 AND B2.







I could do this with triggers/collision. I would just set up a trigger for each grid, check if the collision is happening for A1, A2, B1 AND B2 but I was hoping to do it without using collision and replace it with an array. I guess something like...

check array position A1 - is there an object there? If yes...
check array position A2 - is there an object there? If yes...
check array position B1 - is there an object there? If yes...
check array position B2 - is there an object there? If yes... Finish.

Is that clearer?

4ppleseed

  • Full Member
  • ***
  • Posts: 226
Re: Array to detect if object is covering multiple positions?
« Reply #3 on: April 05, 2016, 04:28:09 AM »
*Bump* - so, should I just use triggers?  ;D

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Array to detect if object is covering multiple positions?
« Reply #4 on: April 06, 2016, 01:39:29 AM »
Hi,

 I think you are getting confused as to where the limit of using arrays and colliders/Trigger is.

 in order to store an information on an array, you need something to happen in the game, and triggers are perfect for this. Why do you want to not use triggers? is it a pure Unity UI game?

in ALL cases, you will need arrays, with or without triggers as your way to watch what happens in the 3d scene,.


Bye,

 Jean

4ppleseed

  • Full Member
  • ***
  • Posts: 226
Re: Array to detect if object is covering multiple positions?
« Reply #5 on: April 06, 2016, 04:21:49 AM »
Thanks Jean, I was just looking to use arrays in a new project so I could learn more about them - but I'll wait until the next project and use triggers in this one  8)