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 Jan_Julius · Sep 29, 2014 at 08:23 AM · raycastbugboolean

bug? with raycasts and booleans

I'm not getting a match when the 2 colors align vertically, and only the top one doesn't work, here is a video of the issue:

https://www.youtube.com/watch?v=r-6cv15d9SU&feature=youtu.be

I have debugged the rays and this is the result of the rays, they ignore the layer the object they are inside in of, when dragged outside this happens

http://i.gyazo.com/ec05f22e2d615aaa1f1c581e993ae4b2.png

Then when next to eachother:

alt text

Here is the code for it, I broke it all up attempting to find what was going on:

 using UnityEngine;
 using System.Collections;
 
 public class Cylinder : MonoBehaviour {
 
     public bool cylinderRay;
     public LayerMask layerToIgnore;
 
     void Start () {
         Color objectColor = renderer.material.GetColor("_Color");
         }
     void Update () {
         Cylinder otherObject;
         Color objectColor = renderer.material.GetColor("_Color");
         RaycastHit hit;
         Vector3 angle0 = transform.TransformDirection(Vector3.up);
         cylinderRay = Physics.Raycast(transform.position, angle0, out hit, 1);
         Debug.DrawRay (transform.position, angle0 * 1, Color.blue);
            if(cylinderRay){
             if(hit.transform.tag == "Cylinder" && !hit.transform.parent.GetComponent<Molecule>().isFalling){
             Color otherObjectColor = hit.collider.renderer.material.GetColor("_Color");
             Molecule molecule = hit.transform.parent.GetComponent<Molecule>();
                 if(objectColor != otherObjectColor){
                     print ("this object isn't the same color as me");
                     if (objectColor == Color.green){
                         transform.parent.GetComponent<Molecule>().GreenCylMatch = false;
                     }
                     if(objectColor == Color.blue){
                         transform.parent.GetComponent<Molecule>().BlueCylMatch = false;
                     }
                     if(objectColor == Color.red){
                         transform.parent.GetComponent<Molecule>().RedCylMatch = false;
                     }
                 }
             if(transform.parent.GetComponent<Molecule>().hasMatches){
                     if(objectColor == otherObjectColor){
                 molecule.hasMatches = true;
                 }
             }
             if(transform.parent.GetComponent<Molecule>().hasMatches 
                    || hit.transform.parent.GetComponent<Molecule>().hasMatches){
                     if(objectColor == otherObjectColor){
                         print ("other object has my color");
                         molecule.hasMatches = true;
                     }
                     transform.parent.GetComponent<Molecule>().matchFound();
                 }
             
 
             if(objectColor == otherObjectColor){
                 
                 if(objectColor == Color.green && otherObjectColor == Color.green){
                         print ("other object is my color and im green");
                         transform.parent.GetComponent<Molecule>().GreenCylMatch = true;
                         hit.transform.parent.GetComponent<Molecule>().GreenCylMatch = true;
                 } 
                 if(objectColor == Color.blue && otherObjectColor == Color.blue){
                         print ("other object is my color and im blue");
                         transform.parent.GetComponent<Molecule>().BlueCylMatch = true;
                         hit.transform.parent.GetComponent<Molecule>().BlueCylMatch = true;
                 } 
                 if(objectColor == Color.red && otherObjectColor == Color.red){
                         print ("other object is my color and im red");
                         transform.parent.GetComponent<Molecule>().RedCylMatch = true;
                         hit.transform.parent.GetComponent<Molecule>().RedCylMatch = true;
                 }
                 }
             } 
         } else {
             print ("ray not hitting anything or incorrect object");
             if (objectColor == Color.green){
                 transform.parent.GetComponent<Molecule>().GreenCylMatch = false;
             }
             if(objectColor == Color.blue){
                 transform.parent.GetComponent<Molecule>().BlueCylMatch = false;
             }
             if(objectColor == Color.red){
                 transform.parent.GetComponent<Molecule>().RedCylMatch = false;
             }
         }
     }
 }

The print it gives me is "Not hitting cylinder or other object is falling", the other object is not falling and that boolean is false, what could be wrong here or am I casting incorrectly? The strangest thing is that not all of them do it, but if they do it it's nearly always the same row and always vertically down, the upper cylinder.

Comment
Add comment · Show 3
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
avatar image Jan_Julius · Sep 30, 2014 at 10:47 AM 0
Share

Bump, I have changed some of my code but it still occurs sometimes.

avatar image khenkel · Sep 30, 2014 at 12:13 PM 1
Share

I'm having problems to understand your problem. Please provide a summary: What should happen? And when? What happens ins$$anonymous$$d?

avatar image Jan_Julius · Oct 01, 2014 at 07:37 AM 0
Share

At all times, when the 2 cylinders are connected they should both light up as that means that they both have found a match with another blue cylinder, sometimes not always the cylinder that is on top will not get the match but the one on the bottom does, when dragged outside the black ball it seems to occur at all times however, the raycast ignores the layer the black ball is on.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by unimechanic · Sep 30, 2014 at 04:24 PM

Make sure that you are not transforming static colliders, that could corrupt the physics scene and make Raycast to return wrong results. See the Static Colliders section:

http://docs.unity3d.com/430/Documentation/Components/DynamicsGroupOverview.html

Comment
Add comment · Share
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

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

27 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to determine direction in order to compare it to raycast results 0 Answers

Line Renderer not showing 0 Answers

Physics.Raycast not hit sometimes 0 Answers

Raycast not detecting ANY HITS AT ALL when starting inside a collider. 0 Answers

Can else statements be nested inside an else statement? 1 Answer


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