- Home /
Check connection to ground algorithm?
Ok so I need some help with this one. I am trying to create a fully destructible system where parts of structures will break if they do not have a connection to the ground. For example, if you knocked out the bottom story of a two story house, the second story should break. However, I am not using physics simulation with this.
So basically I want each object to be able to check the surrounding objects and see if it can trace a path back to the ground. Objects that are on the ground already have a "Grounded" variable I just don't know how to get to trace a path through the connected objects.
I would really appreciate it if someone could point me in the right direction on this one. Is there some sort of algorithm for calculating things like this?
Thanks in advance : )
P.S. I prefer Java Script, but I can probably figure out C# at this point.
it's really unclear what you mean.
to check "surrounding objects", learn about raycasting. search on here for 1000s examples. but that involves using the "physics" in unity - colliders and so on.
it's very strange why you are not just using the physics in Unity. Why use Unity, if not using the physics?
To do what you describe using the built-in physics is trivial.
Unless there are special properties to the objects you can take advantage of, this is a hard problem to solve that may involve reinventing some of the physics engine. For example, if one block is cantilevered and unbalanced, it should fall even though it is connected to the ground. As @Fattie mentions, raycasting would be a potential solution, but imagine a narrow block on top of a large block. You just can't raycast from the center of the large block because the small block may be many places on top of the large block. And the issues go on. If this a general problem, then use the physics engine. If this is a specialized app, then you need to describe it in detail if you want accurate suggestions.
I am well acquainted with raycasting, the problem is passing information across several blocks so that a network of touching blocks can deter$$anonymous$$e if at least one of the blocks in the network is connected to the ground. Preferably in a single function call rather than something that has to run every Update()
That's actually getting way more complex then I actually need. Think $$anonymous$$inecraft blocks, now think $$anonymous$$inecraft trees where you take out the bottom block and the rest does not fall down. That's what I want to solve.
For example this is what I have now:
/Called when a block is broken near us function GetGround() { Debug.Log("Get Ground" + gameObject.name); // skip this test if the object is grounded if(Grounded) { Debug.Log("Block Grounded: Skipping Check"); HasLinkToGround = true; return; } Debug.Log("Setting Link To Ground to false"); //Do not assume link still exists HasLinkToGround = false; //Check all around us TraceAll(); Debug.Log("Trace Data:"); //Check if anything we are touching is connected to the ground for(var i = 0; i < HitAll.length;) { Debug.Log("#" + i); if(HitAll[i] != null) { Debug.Log("Face Has Link To Ground = " + HitAll[i].gameObject.name); if(HitAll[i].HasLinkToGround) { HasLinkToGround = true; return; } } i++; } Debug.Log("No link call break block"); //If not connected break BreakBlock("Lost Link To Ground"); }
The problem is this check only goes one deep because as soon as it hits something that was grounded earlier it returns true even if the block it hit only has a link oto the ground because it is connected to the very block that is trying to see if it is connected to the ground.
I truly recommend you simply look at the huge $$anonymous$$ecraft starter kit freely available on the forums. And the 1000s questions here on $$anonymous$$ecraft
Your answer

Follow this Question
Related Questions
Need an Algorithm to solve the Geometric Puzzle 2 Answers
object destroying 1 Answer
Structural Stability 0 Answers
Combine mesh and merge the neighboring vertices 1 Answer
The algorithm of curve in Shuriken Particle System 2 Answers