- Home /
Box mechanic: Is it possible to know when the box is closed on all margins?
Update 2: I have come up with a solution but I need to know how could I make my AI look into a direction and find the closest object (by tag) to it then calculate the distance to it and repeat the step a couple of times. I will post another question for this particular issue and close this one when I have a proper solution.
Update: I have tried using OverlapSphere to count the collisions -- doesn't work as it sometimes can count more than needed.
I have tried using a box collider around the AI -- same as above.
I have tried making 4 colliders in 4 direction attached to the AI to check for collisions on directions -- also same as above.
Reopened as I've found out that my solution will not provide me with the feature that I want and would become to complex at a point.
Please provide me with any other solutions you may think about!
Hello,
This is going to be a pretty big question. I hope it's not something very hard to do, honestly.
I want a mechanic like this (i already have it -- kinda):
When I click on the screen, the Start Point is created and it instantiates a line/fence, the last piece is considered an End Spot which offer three possibilities of continuing -- any of the other three directions
I'd like to know how could I check if a closed box is created through this mechanic? I want something to happen when the box is closed, how should I go about in doing so? Any info, even tutorials for things that could get me here will receive thumbs up ^_^.
Thanks a lot for any help!
Is your game on a grid? A 2D array backing it? Looks like you can only move NESW, so it is? If so, standard (recursive) graph/grid searches can find connected areas.
Otherwise to search in the fake "world" for gaps is a poorly defined giant pain.
Nope, it isn't on a grid. I want to keep continue working on it without a grid to see what I can come up with but if its absolutely necessary I will set up a grid to sustain it.
Answer by Owen-Reynolds · Jun 23, 2013 at 05:27 PM
If this is a game, I'd have things crawling along the edges -- a simple ray cast & turn left on a hit movement script. Have them ignore each other so they can crawl clock and counterclock-wise, some fast (may miss small gaps) and some slow. They all want to flee off the edge of the map or something. They may be trying to get in or out.
Say the goal is to protect some candy inside the box, which respawns (and you lose points) when it's eaten. You won't know the box is sealed, but if they can't get in or find it difficult to get in, you get lots of candy points, so who cares.
The end may not be exactly what you were thinking, but, especially in a game, it never is.
That's a really great advice! Thank you, but that would change the whole purpose of the game (yes, it is a game).
I am actually trying to capture something with the box, so I want to trigger the "isCaptured" variable when it actually is captured. The thing that needs to be captured is moving around randomly and that is the purpose of the game.
Currently I have 4 colliders(up&down, left&right -- pretty messy but it was just a quick fix for show off) attached to my AI but that doesn't help because it gets captured even if it collides in the exact points without anything else being linked together.
Any other ideas?
@Owen, I am marking your answer as it is the correct one for the question I asked.
I would like to add that I am currently finding a better choice for myself to use Physics.OverlapSphere or a Sphere Collider with a wide radius then check if the number of collisions with the walls and the start/end points are equal to 4 therefore considering it captured.
As you said this is also not the end result expected by me but it is better than changing the whole structure of the game.
Thanks for the help!