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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Hugs Are Drugs · Oct 14, 2012 at 01:31 AM · c#physicsraycastlinerenderer

Bouncing Raycast "Laser" Not Working?

What is wrong with this script? Whenever I run it I get no errors and it runs completely fine, but in game it only shows up as a single line and since it's only a single line I can't tell if it's actually working or not. My only issue with this script is that the lines aren't showing up correctly.

 using UnityEngine;
 using System.Collections;
 
 public class Emission : MonoBehaviour {
             public Vector3 position;
             public static Vector3 staticPosition;
             public Vector3 direction;
             public static Vector3 staticDirection;
     
     void Start () {
             position = transform.position;
             staticPosition = position;
             direction = transform.TransformDirection (Vector3.forward);
             staticDirection = direction;
     } 
     
     void FixedUpdate () {
             LineRenderer lineRenderer = GetComponent <LineRenderer>();
             RaycastHit hit;
         
         if (Physics.Raycast (position, direction, out hit)) {
             lineRenderer.SetVertexCount (2);
             lineRenderer.SetPosition (0, position);
             lineRenderer.SetPosition (1, hit.point);
             position = hit.point;
             direction = Vector3.Reflect (position, hit.normal);    
         }
     
         else {
             position =  staticPosition;
             direction = staticDirection;
         }    
     }
 }

Also, when I use Debug.DrawLine it shows up as a line of the same length except it's constantly blinking. As said, My only issue with this script is that the lines aren't showing up correctly.

Comment
Add comment · Show 6
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 speedything · Oct 14, 2012 at 02:07 AM 0
Share

You are only assigning two vertexes to your line which will only ever give you a single line. To get a line that bounces you'll need a third.

avatar image Hugs Are Drugs · Oct 14, 2012 at 02:22 AM 0
Share

I know that, but shouldn't the two vertexes constantly blink and change position creating a sort of bouncing pulsing line? If not, what do I assign the third vertex's Vector3 to?

avatar image speedything · Oct 14, 2012 at 02:00 PM 0
Share

Ah! Is see what you're trying to do now. $$anonymous$$isunderstood request and assumed you wanted a permanent laser effect.

Have you tried placing Debug.Log(position) at the end of the IF statement? It might reveal if its even being changed.

avatar image Hugs Are Drugs · Oct 14, 2012 at 02:36 PM 0
Share

I'll try that, but since position is public I can view it in the editor and I believe it was changing, it was changing but I don't remember what they were, so I believe it's confirmed to be changing. I'll check in a bit when I get onto my computer.

avatar image Hugs Are Drugs · Oct 14, 2012 at 03:23 PM 0
Share

Also, what way should I use more than one raycast because I think using more raycasts is the only way, the only what I can think of doing it is with an if-if statement, but how do I do that without having to infinifely write if statements inside of itself?

Show more comments

1 Reply

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

Answer by Hugs Are Drugs · Oct 16, 2012 at 02:05 PM

I found the issue, in Vector3.reflect () I put the inDirection as the hit.point of the raycast instead of the initial direction of the raycast, stupid me.

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

10 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

Related Questions

Linerenderer doesn't match my ray. 1 Answer

using A* pathfinding to go to player after raycast has seen it - c# 0 Answers

Raycast problem 1 Answer

Mouse Click + Raycast + Colliders 2 Answers

Change the direction of ScreenPointToRay() Ray 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