- Home /
inside rubicks cube slice problem
Hello!
I'm having a problem I hope somebody can help me solve. I'm working with a modified slice selection script from here (http://answers.unity3d.com/questions/29237/best-way-to-select-rubik-cubes-slice-in-one-go.html) My issue is that I can only select an entire vertical slice if I select a cube on the bottom side of the whole rubicks cube. When I try to select any other cube I get spots where nothing is selected at all.
I'm guessing with the way its set up, It casts a ray up for the column wherever I click, and then for each cube in the column it casts ray to the left and the right. But that leaves everything under the initial up ray unhit and unselected. This also causes problems when I select the middle of a slice, since the is no cube in the center (that's where my character is) I tried adding a downward casting ray but the program won't run when I do.
Can anyone assist? I'll attach the code below since it's highly likely that i'm doing something wrong.
Thanks
var slice = Array();
var Player : Transform;
public var script :AimingRecticle;
function Awake(){
script = GetComponent(AimingRecticle) ;
}
function Update () {
if(Input.GetMouseButtonDown(0)){//triggered by MSDragCube
selectingaSlice();
}
}
var column = Array();
function selectingaSlice(){
slice.Clear();
column.Clear();
column.Add(script.hit.transform);
//vars for rays
var hitsUp: RaycastHit[];
var hitsRight: RaycastHit[];
var hitsLeft: RaycastHit[];
var hitsDown: RaycastHit[];
var up = script.hit.transform.TransformDirection(Vector3.up); //kierunek od DragDirection w MSDragCube
var right = script.hit.transform.TransformDirection(Vector3.right); //kierunek od DragDirection w MSDragCube
var left = script.hit.transform.TransformDirection(-Vector3.right);
var down = script.hit.transform.TransformDirection(-Vector3.up);
//casts up to few cubes
hitsUp = Physics.RaycastAll (script.hit.transform.position, up, 5000.0);
for(var i = 0; i< hitsUp.Length; i++){
var hit: RaycastHit = hitsUp[i];
column.Add(hit.transform);
}
print(column.length+ " in column");
//cast right from each cube
for(var cube: Transform in column){
hitsRight = Physics.RaycastAll (cube.transform.position, right, 10000.0);
for(i = 0; i< hitsRight.Length; i++){
hit = hitsRight[i];
slice.Add(hit.transform);
}
}
//cast left from each cube
for(var cube: Transform in column){
hitsLeft = Physics.RaycastAll (cube.transform.position, -right, 10000.0);
for(i = 0; i< hitsLeft.Length; i++){
hit = hitsLeft[i];
slice.Add(hit.transform);
}
}
print(slice.length+ " in slice");
//colorize
for(var cube: Transform in slice) cube.renderer.material.color = Color.red;
for(var cube: Transform in column) cube.renderer.material.color = Color.red;
}
Your answer
Follow this Question
Related Questions
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer
Have to press Fire1 button twice to run if statement? 1 Answer
Custom Collision Detection 4 Answers
Raycast help..... 2 Answers