playMaker

Author Topic: Get Game object from position?  (Read 4292 times)

neutral

  • Playmaker Newbie
  • *
  • Posts: 5
Get Game object from position?
« on: February 18, 2013, 09:48:25 AM »
Hi,

I have  a grid of cubes and i need to check if the 8 cubes surrounding a specific cube have one value or other in a variable .

How could i do that?
I was thinking that if  can retrieve the Game Object from a position in world space that would be easy.

Is that possible? Is there any other option?

Thanks

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get Game object from position?
« Reply #1 on: February 18, 2013, 12:06:22 PM »
Hi,

What's the purpose?

 I tend to use arrayMaker for this kind of stuff:

I define ID for each of my possible positions, likely two digit string: "11", "12" defining my grid indexes.

then I simply set the value for that key to the gameObject currently on that grid slot. If the gameObject moves under your control, then it's easy to know where it goes as you move it.

If it proves to complicated to find a place in your logic where you can set this, I tend to use colliders as trigger. I have one collider for each grid slot, and everytime a gameObject enters and exit I simply set for that grid in the hashtable the gameObject reference.

 does that make sense?

bye,

 Jean

neutral

  • Playmaker Newbie
  • *
  • Posts: 5
Re: Get Game object from position?
« Reply #2 on: February 18, 2013, 12:18:24 PM »
Hi Jean,

Thanks for your reply.

The purpose it to make a cellular automata , the game on life to be more precise. http://en.wikipedia.org/wiki/Conway's_Game_of_Life
I thought on making the grid with array maker as well, but then i saw this example that you made and i though it was better for this purpose. http://hutonggames.com/playmakerforum/index.php?topic=1358.0

The values of the objects ( color ) have to be changed according to the colours of the objects surrounding it.




neutral

  • Playmaker Newbie
  • *
  • Posts: 5
Re: Get Game object from position?
« Reply #3 on: February 20, 2013, 03:07:57 PM »
I still can´t figure out  how to do this. I´ve managed to create the grid of cubes with array maker, but i don´t know how to cycle through the cubes to check whether their adjacent cubes have one tag or the other .
I´ve managed to cycle parenting the objects and the with get next child but that doesn´t seem to be the right way.
Any idea on how to do this better?
Thanks

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get Game object from position?
« Reply #4 on: March 18, 2013, 09:30:14 AM »
Hi,

 if you draw this grid on a paer with the proper id, then you'll find it easier to work the algorythm out.


say you have a 4 by 4 grid, ( make it 3d when you will understand it in a 2d grid)

each cell is labelled by it's x and y index:

00 10 20 30 40
01 11 21 31 41
02 12 22 32 42
03 13 23 33 43
04 14 24 34 44

so now, say you are in cell 32, if you want to query for adjacent cubes, you need to call:
21, 31, 41, 22, 42,23, 33, 43

if you try to find the mathematical logic behind it, take the x index: 3, you need to query cells that are 1 less than 3, equal to 3 and one more than 3, so 2, 3 and 4
same on the y axis, so you can create an algorythm that count from x-1 to x+1, and inside this loop, you can from y-1 to y+1.

inside this small set of loop, you will need to verify that the cell you construct exists in the first place ( if you are on 34, 35 doesn't exist) , and that you don't check your own cell.

 Does that make sense?

bye,

 Jean

neutral

  • Playmaker Newbie
  • *
  • Posts: 5
Re: Get Game object from position?
« Reply #5 on: March 19, 2013, 06:31:04 AM »
Hi Jean,
Yes it does make sense.
I'll try to put in practice .
Thank you very much.