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 blitzz · Dec 13, 2013 at 07:03 AM · instantiateprefabslightreflection

How to calculate the Angle of incidence on a plane

I was trying to implement the basic reflection laws in unity using C# . I am not getting as in how to calculate the angle of incidence the light ray(line renderer) , so that i can calculate the angle of reflection . void Update () { LineRenderer lineRenderer = GetComponent<LineRenderer>(); BoxCollider2D boxCollider = GetComponent<BoxCollider2D>(); if(isExpanding) { lineRenderer.SetPosition(0,start); end = new Vector3(start.x+Mathf.Cos(Angle)*i,start.y+Mathf.Sin(Angle)*i,0); lineRenderer.SetPosition(1,end); boxCollider.center = new Vector2(start.x+Mathf.Cos(Angle)*i,start.y+Mathf.Sin(Angle)*i); i = i+0.1f; } void OnTriggerEnter2D (Collider2D collider) { var newline = Instantiate(linePrefab) as Transform; RayScript newlineScript = newline.gameObject.GetComponent<RayScript>(); newlineScript.start = end; //newlineScript.end = end; Debug.Log("watt"); newlineScript.Angle = 2.8f; newlineScript.i = 0.1f; isExpanding = false; return; }

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 robertbu · Dec 13, 2013 at 07:14 AM 1
Share

You don't need the angle of incidence. What you need is the inco$$anonymous$$g vector and a vector representing the normal to the surface you want the inco$$anonymous$$g vector to reflect against. If you have both, then you can use Vector3.Reflect() to get the outgoing vector.

avatar image blitzz · Dec 13, 2013 at 08:45 AM 0
Share

any code snippet that you can attach with this as for reference .

avatar image Fornoreason1000 · Dec 13, 2013 at 09:19 AM 1
Share

listen to what Robertbu is saying and you shouldn't need a snippet, these are the skills you need as a programmer(i understand that you new, im just giving you a criteria to help you). you need to apply any sort of math skills(remember those thing you thought you would never use in real life? well you'll probably use them now!) and logical reasoning to an algorithm that you can convert to code.

  1. get inco$$anonymous$$g vector, you should already have this. if you don't then rethink approach and find a method that nets you the inco$$anonymous$$g vector, you need it to reflect against the normal vector.

  2. get normal vector (hit.normal), this happens after your ray cast, you will need to assign a Raycast hit of course.

  3. uses Vector3.Reflect() var reflect = Vector3($$anonymous$$yInputVecotr, hit.normal)

what robertbu is saying in short is, get you ray cast vector, get hit.normal and use them in Vector3.Reflect, which will return your desired Vector.

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

17 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

Related Questions

Instantiate Reference Problem 1 Answer

Prefabs wont instantiate using a for loop? 1 Answer

instantiate prefabs/gameObjects 1 Answer

How to instantiate the prefabs on grid in Unity? 1 Answer

Spawning letter tiles evenly across screen 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