playMaker

Author Topic: Finding nearby neighboring objects  (Read 3325 times)

mweyna

  • Full Member
  • ***
  • Posts: 242
Finding nearby neighboring objects
« on: June 22, 2013, 05:22:14 PM »
So I'm trying to create a Dungeon Keeper esc style game. Right now I'm working on the room building code, and hit a bit of a wall.

I have an FSM on a block with 9 different states, empty, corner right, left, etc. I want to automatically detect what boxes are nearby to have it switch to the appropriate corresponding shape. Each state sets an INT Value - 0 to 9. How would I detect what other 9 blocks are nearby (their game object names) so that I can pull their corresponding INT values?



jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15620
  • Official Playmaker Support
Re: Finding nearby neighboring objects
« Reply #1 on: June 24, 2013, 07:03:49 AM »
Hi,

Have you checked ArrayMaker? it has a sample that finds the closest object in real time. you can certainly apply the routine for your need.

https://hutonggames.fogbugz.com/default.asp?W715

bye,

 Jean

mweyna

  • Full Member
  • ***
  • Posts: 242
Re: Finding nearby neighboring objects
« Reply #2 on: June 25, 2013, 02:16:37 AM »
So I managed to basically write up a psuedo-array using short raycasts in the appropriate directions, and that seems to be working for me well enough. The problem I get stuff at now, and maybe ArrayMaker has the capacity to help me solve this is how to turn a block into the appropriate shape.

Grid is a variable size, not locked down yet.

For the sake of discussion, the tile should be aware of nearby neighbors to switch to corresponding art.

2 3 4
9 0/1 5
8 7 6

State 0 - Full block
State 1 - Floor
State 2 - Corner_Top_Left
State 3 - Wall_Top
State 4 - Corner_Top_Right
State 5 - Wall_Right_Side
State 6 - Corner_Bottom_Right
State 7 - Wall_Bottom
State 8 - Corner_Bottom_Left
State 9 - Wall_Left

So right now I've been using a heavily playmaker driven system to accomplish the following:

Using short raycasts in each direction finds the nearby object name and stores it to dynamic name (once on level load and then again if anything is "updated").
Using dynamic names, get's the current state of each square and stores it in a BOOL object (3.3 would be square 3, state 3)

Where my brain is falling apart is then writing the logic to turn the squares into the appropriate shapes based on everything else. Outside of writing thousands of conditional statements If 3,1 and 4,5, etc do this. how would anyone suggest approaching this problem?

- Ian

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15620
  • Official Playmaker Support
Re: Finding nearby neighboring objects
« Reply #3 on: June 25, 2013, 02:33:03 AM »
Hi,

If your neighbors arts doesn't follow a logic ( like it is a predefined maze for example), Simply maintain look up tables.

 have an HashTable ( from arrayMaker) with the following

"3.0"->artwork reference
"3.1"->artwork reference
etc

If your artwork follows a logic, then it's best if you implement it without Look up tables.

Also, I am working on an xml system, which would likely comes handy here for you, if you think that defining your maze with xml ( or json, I have it cooking too), let me know, I'll send you a package. I want to make this available soon, but needs polishing.


bye,

 Jean

mweyna

  • Full Member
  • ***
  • Posts: 242
Re: Finding nearby neighboring objects
« Reply #4 on: June 25, 2013, 02:45:20 AM »
So I've basically mimic'd that in a brute force non-programmer way. Right now, each block has ten objects under it (it's just a prefab). Each object represents the different states it needs. So when 3.1 is true, it's simply turning off the renderability of the other pieces.

What I'm failing to see is how an array or hash table can help craft the logic to know if my neighbor is this state, I'm this state. The more I think I just need to know the states of 4 neighbors, 3,5,7, and 9. However when you account for each of those having 10 states, it still comes to a simply mind boggling amount of combinations to have to code up.

So if we have a string (3.2, 5.1, 7.5, 9.3) become state XX. But writing up all combinations seems like a herculian effort.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15620
  • Official Playmaker Support
Re: Finding nearby neighboring objects
« Reply #5 on: June 25, 2013, 03:04:06 AM »
Hi,

 indeed this is the wrong way to do this. You need to do this using logics

if you are on 3.4 and wants to check the slot on the right side, you need to check 4.4 that is adding 1 to the x value.

ArrayMaker can help you define the content of each of these slots, that will have to be defined somehow, be it in xml, in ArrayMaker or in individual states.


Maybe you could explain what is the goal of the game and what happens, then we can discuss the best way, right now I am not sure how all that your explained fits into the game system.

bye,

 Jean