Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 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 /
  • Help Room /
avatar image
0
Question by Ochreous · Jun 02, 2016 at 10:26 PM · c#collidermesh3dlinerenderer

C# 3D Collider Without Fixed Points or use Mesh Filter Instead?

I have a script that randomly draws a Line Renderer into a beam like lightning and I want to implement a 3d collider into the script. But all the 3d colliders except for the mesh collider appear to have fixed points and the LineRenderer isn't a mesh so it won't work with the Mesh Collider. There isn't a 3d version of the Edge Collider either so that's out. Do I need to convert my script to using a Mesh Filter instead of a Line Renderer or are there 3d Colliders that aren't fixed?

 using UnityEngine;
 using System.Collections;
 
 public class BeamShooter : MonoBehaviour {
     // Prefabs
     public Transform beamPoint;
     public Transform beamPointOrigin;
     public LineRenderer lineRndr;
     // Timing
     public float timeToUpdate = 0.05f;
     public float timeToPowerUp = 0.5f;
     
     public int maxNumVertices;
     public int numVertices;
     public float lastUpdate;
     
     // Use this for initialization
         void Awake() 
     {
         lineRndr = GetComponent<LineRenderer>();
         numVertices = 0;
         lastUpdate = 0.0f;
     }
 
     // Update is called once per frame
     void Update () {
         if( Input.GetButton("Fire1") ) {
             if ((Time.time - lastUpdate) < timeToUpdate)
                 return;
             lastUpdate = Time.time;
             if(numVertices < maxNumVertices){
                 numVertices = Mathf.RoundToInt(Vector3.Distance(transform.position, beamPoint.position));
                 beamPoint.Translate(Vector3.forward * 5 * Time.deltaTime * (1.0f / timeToPowerUp));
             }
             Vector3 currentV = transform.localPosition;
             lineRndr.SetVertexCount(numVertices);
             for (int i = 0; i < numVertices; i++) {
                 float vfl = (Random.value * 4.0f - 2.0f);
                 Vector3 v = new Vector3(
                 currentV.x + vfl,
                 currentV.y + vfl,
                 currentV.z + vfl
                 );
                 lineRndr.SetPosition(i, v);
                 currentV += (beamPoint.localPosition - transform.localPosition) / numVertices;
             }
             lineRndr.SetPosition(0, transform.localPosition);
         }
         if(Input.GetButtonUp("Fire1")){
             numVertices = 0;
             lineRndr.SetVertexCount(0);
             beamPoint.transform.position = beamPointOrigin.position;
         }
     }
 }
 
Comment
Add comment · Show 1
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 Le-Pampelmuse · Jun 03, 2016 at 04:12 AM 2
Share

What exactly is the question here, do you want your lightning to have some sort of collider so it can interact with objects as it strikes? Use raycasting for the parts of the lightning, would be my advice. Don't start to mess around with mesh colliders that cost you more performance than you have..

3d Colliders are primitive shapes like box, sphere, capsule, wheel, etc..but they can be manipulated to some degree. They aren't fixed to their starting shape.

You could naturally use a thin capsule collider than spans across two points of the line, as it can be resized in radius and height.

I suggest you read up on 3D colliders:

https://unity3d.com/learn/tutorials/topics/physics/colliders

http://docs.unity3d.com/$$anonymous$$anual/CollidersOverview.html

etc..

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

157 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 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 avatar image

Related Questions

OnTriggerEnter Issue - Collider problem 0 Answers

Hiding part of mesh 0 Answers

Can someone please help me with mesh extrusion 0 Answers

How do i use lines to calculate triangles on mesh?? 0 Answers

How do i calculate mesh on a spline?? 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