Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Riiich · Mar 25, 2015 at 02:05 PM · raycastvector3raycasthitreflection

Stop the lasers from keep bouncing

So I'm using the script found here: Unity Raycast Reflection but I can't get it to stop bouncing. I've tried using a simple:

 if(lastHit != "OutWall") {
     //the reflection direction is the reflection of the current ray direction flipped at the hit normal
     inDirection = Vector3.Reflect(ray.direction,hit.normal);
     //cast the reflected ray, using the hit point as the origin and the reflected direction as the direction
     ray = new Ray(hit.point,inDirection);
 
     //Draw the normal - can only be seen at the Scene tab, for debugging purposes
     Debug.DrawRay (hit.point, hit.normal*3, Color.blue);
     //represent the ray using a line that can only be viewed at the scene tab
     Debug.DrawRay (hit.point, inDirection*100, Color.magenta);
 
     //Print the name of the object the cast ray has hit, at the console
     Debug.Log("Object name: " + hit.transform.name);
     
     //save the last hit object
     lastHit = hit.transform.name;
 
     //if the number of reflections is set to 1
     if(nReflections==1)
     {
         //add a new vertex to the line renderer
         lineRenderer.SetVertexCount(++nPoints); 
     }
 
     //set the position of the next vertex at the line renderer to be the same as the hit point
     lineRenderer.SetPosition(i+1,hit.point);
 }

But adding my lastHit variable doesn't seem to be working.

Could you guys take a look at his script and determine where I should place my "If OutWall is hit then don't continue bouncing" if statement

Thanks so much for your help!

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Riiich · Aug 31, 2021 at 11:50 PM

This was correct, I was using a tag instead of the GameObject's name

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

2 People are following this question.

avatar image avatar image

Related Questions

Not getting right value; ScreenPointToRay 0 Answers

RayCast Hit Point rounding itself...? 1 Answer

Shoot Raycast to a specified Angle 0 Answers

Using raycast - Why can't I get a variable on the object I hit? 1 Answer

Only One LineRenderer Renders 0 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