- Home /
Can i destroy this cube? Logic??
Hi,
How can i check if there is any cubes "floating". Easier to explain the problem if i show you some examples.

Example 1: I wanna remove cube 1. I shouldn't be able to, because cube 2 will be floating, i could check this by looping through all cubes and see if there is anybody that isn't colliding with a cube, and if there is its a no go. But that method doesn't work because of example 2.
Example 2: I wanna remove cube 6. Now the colliding method doesn't work here because even though 7,8,9 and 10 are floating they are still colliding with a cube.
Hmm, i find this hard to explain. So basically, you can click on any cube to destroy it, but you shouldn't be able to destroy it if there is any cubes "floating" after the cube gets destroyed.
Also, all these cubes are build by the player so i can't predict they're positions. And they can be build in ANY form.
How can i check this? I have no idea my brain doesn't work right now! I would appreciate any help i can get!
Answer by midomido · Jan 29, 2014 at 01:25 PM
Maybe you can raycast to see if the cube is standing on another cube ?
bool IsGrounded(){
return Physics.Raycast(transform.position,-Vector3.up, CubeLength); }
I tried that but it won't work because the cube can be placed anywhere on the screen as long as it is touching another cube so it can be right at the corner of another cube, it can be below,the sides and in the middle of 2 cubes.
EDIT: Even if i succeeded at checking if it is touching another cube and that cube is touching another cube and so on... How would i know if they are not connected to the main piece(cube 0).
Try doing 4 ray casts up down left right from the cube position when you try to delete it
Your answer