using System.Collections; using System.Collections.Generic; using UnityEngine; [RequireComponent(typeof(LineRenderer))] public class Ellipse : MonoBehaviour { LineRenderer lr; [Range(3,36)] public int segments; public float xAxis = 5f; public float yAxis = 3f; void Awake() { lr = GetComponent(); CalculateEllipse(); } void CalculateEllipse() { Vector3[] points = new Vector3[segments + 1]; for (int i = 0; i < segments; i++) { float angle = ((float)i / (float)segments) * 360 * Mathf.Deg2Rad; float x = Mathf.Sin(angle) * xAxis; float y = Mathf.Cos(angle) * yAxis; points [i] = new Vector3(x, y, 0f); } points [segments] = points [0]; lr.positionCount = segments + 1; lr.SetPositions (points); } void OnValidate() { if (Application.isPlaying) CalculateEllipse(); } } You're welcome! :)
@Max298473 жыл бұрын
god
@HadiNauf2 жыл бұрын
very cool
@louismarriott45643 жыл бұрын
Thanks a lot for this tutorial! I combined this with a lot of maths to generate ellipses rotated around a focii for the orbits of planets :D
@HadiNauf2 жыл бұрын
hi, I tried this on my planet game object, so it will look like it has an orbital line around the sun. it works, but when i move object. the position of the orbital line does not move with the object being moved. i tried inserting the script into the game object, but still getting the same problem
@torktumlarn13647 жыл бұрын
why dont you put the code in the description??? D:
@meh5364 жыл бұрын
So you watch it and learn something instead of just copying the code
@beastbomber23164 жыл бұрын
@@meh536 ezactly
@rolfvanderbijl3 жыл бұрын
For some reason I get a nullrefference error before the script (in Awake) can get the linerenderer component. I solved it by making it public and dragging and dropping the gameObject but isn't there something I did wrong?
@Rechdan7 жыл бұрын
Great tutorial! Can't wait for the next video! :D
@BoardToBitsGames7 жыл бұрын
Nelson F. Rechdan should be up this time next week!
@Rechdan7 жыл бұрын
Excellent, I'm looking forward to make a game in space :D
@meh5364 жыл бұрын
Very Nice! Showing all the code and the writing of it really helps noobs like me, instead of just showing random snippets :D
@NoblesseCheung7 жыл бұрын
How can I use this ( lr.positionCount & lr.SetPosition) in unity 5.4?
@bguilleminot4 жыл бұрын
I'm using Unity 2018.4.19f and I can't add the code line: if (Application.IsPlaying) It triggers the error: "Returns true if the given object is part of the playing world either in any kind of built Player or in Play Mode." Any suggestions?
@mrroams58124 жыл бұрын
My OnValidate is being called before Start and Awake so I am getting a NullReferenceException on the LineRenderer. I'm fairly new to Unity and have never used OnValidate before so I'm wondering why it's working in the video but not for me? In the mean time, I'll just not use OnValidate.
@ArinA-di6wn6 жыл бұрын
'UnityEngne.LineRenderer' does not contain a definition for 'positionCount' and no extension method 'positionCount' accepting a first argument of type 'LineRenderer' could be found (are you missing a using directive or an assembly reference?). Why? how to resolve it?
@lordciciu6 жыл бұрын
Works with older unity versions too?
@Dolmek6 жыл бұрын
[Solved]I've a problem: I'm trying to draw an orbit of one moon around one planet but the orbit is placed around the sun instead of the planet. I placed the moon ad a child of the planet, and the planet is not a child of the sun. Edit: In case some one else need it I solved in this way: where there is in void CalculateElliplse() lr.positionCount = segments + 1; add this line lr.useWorldSpace = false;
@BoardToBitsGames6 жыл бұрын
Jonny Othman it’s been awhile since I wrote this, but I believe the orbit is based on a point in world space, not local space, so you’d need to shift it to the planet’s center and calculate the position.
@Dolmek6 жыл бұрын
@@BoardToBitsGames I found, it litterally 2 min before read this post. It needed to be add in CalculateElliplse() the line lr.useWorldSpace = false;
@bhaveshtiwari57836 жыл бұрын
You are great
@joanofarc22767 жыл бұрын
awesome!
@BomTailey7 жыл бұрын
Hey, really like your video, but just as heads-up in future that your videos are reeeeeeally quiet compared to most videos on youtube - even at 100% YT volume! do a comparison of any other video at 50% volume whilst listening to your own vids at 100% as an example. This isn't much an issue in a quiet environment, but any background noise IRL or from people on voip drowns it out quickly.
@torktumlarn13647 жыл бұрын
i dont see what im doing wrong.... using System.Collections; using System.Collections.Generic; using UnityEngine; [RequireComponent(typeof(LineRenderer))] public class Ellipse : MonoBehaviour { LineRenderer lr; [Range(3, 36)] public int segments; public fload xAxis = 5f; public float yAxis = 3f; void Awake() lr = GetComponent (); CalculateEllipse (); } void CalculateEllipse(){ Vector3[] points = new Vector3[segments + 1]; for (int i = 0; i < segments; i++) { float angle = ((float)i / (float)segments) * 360 * Mathf.Deg2Rad; float x = Mathf.Sin (angle) * xAxis; float y = Mathf.Cos (angle) * yAxis; points[i] = new Vector3(x, y, 0f); } points[segments] = points [0]; LineRenderer.positionCount = segments + 1; LineRenderer.SetPositions (points); } void OnValidate(){ CalculateEllipse (); } }
@MrKrystian0107 жыл бұрын
first thing first you should change LineRenderer.positionCount = segments + 1; LineRenderer.SetPositions (points); to lr.positionCount = segments + 1; lr.SetPositions(points);
@torktumlarn13647 жыл бұрын
i had it set to that i just changed it to see if that was it
@MrKrystian0107 жыл бұрын
ok so try this, this should work just paste this correctly under: points[segments] = points[0]; and this should work correctly from now on :) lr.positionCount = segments + 1; lr.SetPositions (points); } void OnValidate() { if (Application.isPlaying && lr != null) { CalculateEllipse(); } } }
@torktumlarn13647 жыл бұрын
can you just type copy past your hole code here it dosent seem to work for me i dont know why
@MrKrystian0107 жыл бұрын
Sure here you go, I hope it'll work for you :) using UnityEngine; [RequireComponent(typeof(LineRenderer))] public class EllipseRenderer : MonoBehaviour { LineRenderer lr; [Range(3, 36)] public int segments; public fload xAxis = 5f; public float yAxis = 3f; void Awake() { lr = GetComponent(); CalculateEllipse(); } void CalculateEllipse() { Vector3[] points = new Vector3[segments + 1]; for (int i = 0; i < segments; i++) { float angle = ((float)i / (float)segments) * 360 * Mathf.Deg2Rad; float x = Mathf.Sin (angle) * xAxis; float y = Mathf.Cos (angle) * Axis; points[i] = new Vector3(x, y, 0f); } points[segments] = points[0]; lr.positionCount = segments + 1; lr.SetPositions(points); } void OnValidate() { if (Application.isPlaying && lr != null) { CalculateEllipse(); } } }
@a_soulspark7 жыл бұрын
I'd like to be a patron but I have no money :(
@BoardToBitsGames7 жыл бұрын
+Pedro Brito no worries! As long as you're watching and learning something, I'm good!
@MaxStranger74 жыл бұрын
It looks like your formula is a bit wrong, doesn't it? en.wikipedia.org/wiki/Parametric_equation
@a_soulspark7 жыл бұрын
"Understandfing Ellipses"?
@BoardToBitsGames7 жыл бұрын
+Pedro Brito its German, I think XD
@jonjimihendrix6 жыл бұрын
"We're making video games here, so we can ignore physics." 😃🙃😃
@VR360TV4 жыл бұрын
Another video that does not contain the script in the description, what a waist of time. it would take you 2 seconds to past the script in the description...
@thetruemystic_2 жыл бұрын
Or actually watch the video, learn how it works instead of just wanting to grab and go. You've got a lot of learning to do.