Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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.

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

Have to press Fire1 button twice to run if statement? 1 Answer

Custom Collision Detection 4 Answers

Raycast help..... 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges