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
0
Question by darryldonohoe · Nov 15, 2016 at 03:58 PM · raycastlistanglelinerendererhit

Help with casting and drawing multiple raycast along an angle

hey there,

Like the title says, i want to cast multiple Ray's along an angle. And draw them using a LineRenderer.

I hope someone can help me with this one, i find it pretty hard to come up with a solution. The script is meant for a weapon set in a top down shooter. I am trying to create a variety of weapons each with their own variables.

Some will have 1 bullet trace while others can spread 5 or more on a certain angle.

I tried it doing like this:

                         //this snippet is placed in an IEnumerator : Shoot(int amount, float spreadAngle, int count)
                         //the reason it is a IEnumerator is because some weapons will have a Burst fire type
                         //the AMOUNT variable is set for the amount of bullets fired
                         //SPREADANGLE variable is self explanatory, this will be the angle the bullets will be fired in
                         //COUNT variable is for the Burst function, 1 is just a regular weapon, 3 will have a burst of 3 bullets
                         float perRayAngle = spreadAngle / (amount - 1);     //perRayAngle will evenly spread the Ray's along the angle
                         float startAngle = spreadAngle * -0.5f;
 
                         //I thought maybe using a List will help solve this, but it didn't
                         List<LineRenderer> lines = new List<LineRenderer>(amount);
 
                         
                         for(int i = 0; i < amount; i++)
                         {
                             //couldn't check if the rayAngle was working, since when i pressed the Fire1 button it gave a null reference
                             Vector3 rayAngle = Quaternion.AngleAxis(startAngle+1*perRayAngle,fireTransform.forward) * fireTransform.forward;
 
                             //the Ray values
                             shootRay.origin = fireTransform.position;
                             shootRay.direction = rayAngle;
 
                             //bulletLine is a public LineRenderer, lines[i] will inherit its values
                             lines[i] = bulletLine;
                             //enable lines[i]
                             lines[i].enabled = true;
                             //set the lines[i] starting position to the fireTransform or "Muzzle" position
                             lines[i].SetPosition(0, fireTransform.position);
 
                             //for now i only draw the lines when it is hit, i will change this however
                             if(Physics.Raycast(shootRay, out shootHit, 100f))
                             {
                                 lines[i].SetPosition(1, shootHit.point);
                             }
 
                         }
 
                         //firerate
                         nextFire = Time.time + fireRate;


I thought using a List will help this problem, since the amount of bullets fired change depending on the weapon.

However, it still didn't work. Whenever i press the "Fire1" key, i get a null reference.

So anyway, hope you can give me a few tips on this.

Cheers and thanks in advance, Darryl

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

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

78 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 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 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

Help with LineRenderer 1 Answer

A node in a childnode? 1 Answer

Hit Angle Of Ray to Surface? 1 Answer

hit point not working correctly . 1 Answer

Hover Effect with more rays as turbines? 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