Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by nauman001 · Jan 16, 2017 at 08:25 AM · physicsbouncereflectionslaser beammirrorreflection

how can i reflect laser(Line Renderer) with the help of multiple mirrors in 3D?

hey guys,i'm building a game in 3D in which i had a source of laser, multiple mirrors and a cube and lets say that the cube is my target.i'm kinda new to unity and i have checked all other answers related to reflection stuff but they didn't work for me. alt text this is my project and following are my problems in which i want help,

1) i want that i press space bar and laser starts.

2) i want to reflect laser when it hit the blue area on the mirror but when the grey area comes laser should terminate.

3) same goes for other mirrors but i want multiple reflections and when laser hit the cube it should terminate.

here is my code for laser. alt text Kindly please help me i'll be very thankful.

image2.png (318.5 kB)
image3.png (20.0 kB)
Comment
Add comment · Show 5
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 doublemax · Jan 16, 2017 at 08:27 AM 1
Share

Please post code as text and not a fraction of it as screenshot.

avatar image nauman001 doublemax · Jan 16, 2017 at 08:32 AM 0
Share

sure.sorry about that

avatar image nauman001 doublemax · Jan 16, 2017 at 08:48 AM 0
Share
 using UnityEngine;
 using System.Collections;
 
 public class Laser : $$anonymous$$onoBehaviour 
 {
     private LineRenderer lr;
 
 
     // Use this for initialization
     void Start () 
     {
         lr = GetComponent<LineRenderer> ();
     }
     
     // Update is called once per frame
     void Update ()
     {
             Fire ();
     }
 
     void Fire()
     {
         RaycastHit hit;
 
         if (Physics.Raycast (transform.position, transform.forward, out hit)) 
         {
             if (hit.collider)
             {
                 lr.SetPosition (1, new Vector3 (0, 0, hit.distance));
             }
             if (hit.collider.tag == "Cube") 
             {
                 Vector3 reflectLaser = Vector3.Reflect (transform.position, hit.normal);
             }
         }
         else
         {
             lr.SetPosition(1, new Vector3(0, 0, 5000));
         }
     }
 }
 
avatar image nauman001 doublemax · Jan 16, 2017 at 08:56 AM 0
Share

the tag "cube" is the blue part of the mirror.i'm new to this so can you write code for me? i've tried everything but didn't work.Please help

avatar image doublemax nauman001 · Jan 16, 2017 at 09:08 AM 1
Share

I'm not going to write the whole code for you, sorry.

In more or less pseudo code it could look like this:

 bool ray_ter$$anonymous$$ated = false;
 Vector3 ray_position = transform.position;
 Vector3 ray_direction = transform.forwad;
 
 while ( !ray_ter$$anonymous$$ated )
 {
     cast ray using ray_position and ray_direction
     if( hit anything )
        set next linerenderer point to hit position
     else
        set next linerenderer point to some point in the far distance in the direction of the ray
        
     if( hit mirror )
       set ray_position to hit position
       set ray direction to reflected vector
     else
       ray_ter$$anonymous$$ated = true
 }

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by evrolittlegames · Sep 15, 2020 at 06:39 AM

Check this tutorial https://youtu.be/pgDsOeo31Q0

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

6 People are following this question.

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

Related Questions

How could I make a bouncy object move mostly along the Z axis? 1 Answer

Bouncing Ball and Walls 1 Answer

Cant find options to change physic material to bouncy 2 Answers

RIGIDBODY HOW MAKE IT STOP BOUNCING HELP! 3 Answers

Reducing bounce on simple boxes 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