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 smirlianos · Nov 16, 2014 at 03:36 PM · raycastrayhitvoxel

[Unsolved] Raycast isn't casting

Hello,

I make a voxel game, which there is a 100x3x100 area of cubes. I want the cubes that have another cube on top of them to be invisible, for performance issues. I cast a ray from each cube to check if there is another cube on top, but it isn't casyed at all. What's the problem?

 #pragma strict
 private var pl : Transform;
 private var meshComp : MeshRenderer;
 
 function Awake () {
     var plObj = GameObject.Find("Player");
     pl = plObj.transform;
     meshComp = gameObject.GetComponent(MeshRenderer);
 }
 
 function Update () {
     if(Vector3.Distance(gameObject.transform.position, pl.position) > 20)
     {
         meshComp.enabled = false;
     }
     else
     {
         var fwd = transform.TransformDirection(Vector3.up);
         var hit : RaycastHit;
         if (Physics.Raycast(transform.position, fwd, hit, 1))
         {
             print ("There is something in front of the object!");
             meshComp.enabled = false;
             Debug.DrawLine (transform.position, hit.point, Color.cyan);
         }
     }
 }
Comment
Add comment · Show 9
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 ExtremePowers · Nov 16, 2014 at 04:03 PM 0
Share

Shouldn't this line

 var fwd = transform.TransformDirection(Vector3.up);

Be this ins$$anonymous$$d?

 var fwd = transform.TransformDirection(Vector3.forward;
avatar image smirlianos ExtremePowers · Nov 16, 2014 at 04:29 PM 0
Share

No, I want to check on top of the object. The variable name is wrong!

avatar image robertbu · Nov 16, 2014 at 06:10 PM 1
Share
  • You have colliders on all the object?

  • You've placed a Debug.Log() in the 'else' to verify that it is firing?

  • You've verified that this script is on all the blocks?

Note that you are doing 30,000 raycasts per frame if this script is on all your blocks.

avatar image smirlianos · Nov 16, 2014 at 06:38 PM 0
Share

Actually, I raycast from blocks that are close to the player. And yes, every cube has collider and the script. Also the Debug.DrawLine doesn't work as well. It doesn't display any line.

avatar image robertbu · Nov 16, 2014 at 06:45 PM 0
Share

So you begin to verify. Put a Debug.Log() in both halves of your if() else() block to see which one is firing. Put a Debug.DrawRay(transform.position, fwd * 1.0) to verify you are casting in the direction you expect and that your Raycast() is long enough. View your blocks in Scene view to verify the collider is aligned and sized to the blocks.

avatar image smirlianos · Nov 16, 2014 at 07:17 PM 0
Share

After some research, I found out that if the player is on top, the block is destroyed. The problem is that it doesn't work with cubes on top... -.- Debug.Logs work, but again, if the object on top is the player...

Show more comments

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

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

Related Questions

I don't know why i can't detect by ray sth. tagged, 1 Answer

Raycast isn't working on small distances 1 Answer

how to get info on what raycast hitted 1 Answer

Raycast on mini-map 0 Answers

Exclude tag from raycast 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