- Home /
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);
}
}
Well, If u figured this out please share your knowledge with me :D
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.
Your answer
Follow this Question
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