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 Scorpoid · Feb 22, 2017 at 08:30 AM · linerenderersplinelightningcurved path

Create a line renderer along a Bezier Curve/ Spline

I am mid level coder, this is the most complicated thing I have done and I feel like it was quite a jump from what I have previously done.

I am working on a VR wizard game and one of the spells is lightning. I am trying to create lightning that will spawn instantly going from the end of the player's wand to the enemy.

So far I have a bezier drawn in the editor using Handles.DrawBezier that works fine but I can not seem to figure out how to make it so the player can see this line in game (using a line renderer) . Later I will randomly change these points every frame so that it will actually look like lightning.

I am open to any ideas.

This is the Editor Script

[CustomEditor(typeof(Lightning2))] public class Lightning2Inspector : Editor {

 private Lightning2 lightning2;
 private Transform handleTransform;
 private Quaternion handleRotation;

 private void OnSceneGUI()
 {

    lightning2 = target as Lightning2;
    
     Vector3 p0 = lightning2.points[0]; 
     Vector3 p1 = lightning2.points[1]; 
     Vector3 p2 = lightning2.points[2]; 
     Vector3 p3 = lightning2.points[3]; 
       
     Handles.color = Color.gray;
     Handles.DrawLine(p0, p2); //draws the start tangent
     Handles.DrawLine(p1, p3); //draws the end tangent

     Handles.DrawBezier(p0, p1, p2, p3, Color.blue, null, 2f);
 }

}

This the script on an empty game object attached to the wand

 public class Lightning2 : MonoBehaviour {
     LineRenderer lineRenderer;
     public Vector3[] points;
     Vector3 enemy;
     
     private void Start()
     {
         lineRenderer = GetComponent<LineRenderer>();
     }
     void Update()
     {
         
         enemy = GameObject.FindGameObjectWithTag("Enemy").transform.position;
 
         points[0] = transform.position;   //start position
         points[1] = enemy + Vector3.up;   //end position
         points[2] = transform.position + Vector3.forward; //start tangent
         points[3] = enemy + Vector3.back + Vector3.up;  // end tangent
 
         lineRenderer.SetPositions(points);
     }
     
 }
 




Comment
Add comment · Show 2
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 Menyus777 · Jul 10, 2017 at 09:56 PM 0
Share

Well, If u figured this out please share your knowledge with me :D

avatar image Scorpoid Menyus777 · Jul 12, 2017 at 03:54 PM 0
Share

I couldn't figure it out, and it seems like no one else has too:). I just ended up making a straight line render that randomly jumped around to make it seem a bit more like lightning. If anyone has an answer, I would still love to know.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Thread Modes Spawn Objects of differing lengths uniformly along a Spline 0 Answers

How to make spline and move object along the spline 1 Answer

Make a dynamic visual link between two game objects 1 Answer

I need to make a bullet prefab follow a set path(bezier angle) on an invisible line renderer 0 Answers

Generate a mesh around a LineRenderer 2 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