• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by hanaharu7 · Feb 23, 2014 at 12:40 AM · javascriptraycastselectrubikscube

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;
     }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

The name 'Raycast' does not denote a valid type ('not found') 1 Answer

Make Raycast that ignores certain tags? 0 Answers

How to fix a small raycast issue? 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges