Orbit Paths in Unity: Understanding Ellipses

  Рет қаралды 34,504

Board To Bits Games

Board To Bits Games

Күн бұрын

Пікірлер: 45
@GeorgTheGr8
@GeorgTheGr8 6 жыл бұрын
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! :)
@Max29847
@Max29847 3 жыл бұрын
god
@HadiNauf
@HadiNauf 2 жыл бұрын
very cool
@louismarriott4564
@louismarriott4564 3 жыл бұрын
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
@HadiNauf
@HadiNauf 2 жыл бұрын
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
@torktumlarn1364
@torktumlarn1364 7 жыл бұрын
why dont you put the code in the description??? D:
@meh536
@meh536 4 жыл бұрын
So you watch it and learn something instead of just copying the code
@beastbomber2316
@beastbomber2316 4 жыл бұрын
@@meh536 ezactly
@rolfvanderbijl
@rolfvanderbijl 3 жыл бұрын
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?
@Rechdan
@Rechdan 7 жыл бұрын
Great tutorial! Can't wait for the next video! :D
@BoardToBitsGames
@BoardToBitsGames 7 жыл бұрын
Nelson F. Rechdan should be up this time next week!
@Rechdan
@Rechdan 7 жыл бұрын
Excellent, I'm looking forward to make a game in space :D
@meh536
@meh536 4 жыл бұрын
Very Nice! Showing all the code and the writing of it really helps noobs like me, instead of just showing random snippets :D
@NoblesseCheung
@NoblesseCheung 7 жыл бұрын
How can I use this ( lr.positionCount & lr.SetPosition) in unity 5.4?
@bguilleminot
@bguilleminot 4 жыл бұрын
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?
@mrroams5812
@mrroams5812 4 жыл бұрын
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-di6wn
@ArinA-di6wn 6 жыл бұрын
'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?
@lordciciu
@lordciciu 6 жыл бұрын
Works with older unity versions too?
@Dolmek
@Dolmek 6 жыл бұрын
[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;
@BoardToBitsGames
@BoardToBitsGames 6 жыл бұрын
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.
@Dolmek
@Dolmek 6 жыл бұрын
@@BoardToBitsGames I found, it litterally 2 min before read this post. It needed to be add in CalculateElliplse() the line lr.useWorldSpace = false;
@bhaveshtiwari5783
@bhaveshtiwari5783 6 жыл бұрын
You are great
@joanofarc2276
@joanofarc2276 7 жыл бұрын
awesome!
@BomTailey
@BomTailey 7 жыл бұрын
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.
@torktumlarn1364
@torktumlarn1364 7 жыл бұрын
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 (); } }
@MrKrystian010
@MrKrystian010 7 жыл бұрын
first thing first you should change LineRenderer.positionCount = segments + 1; LineRenderer.SetPositions (points); to lr.positionCount = segments + 1; lr.SetPositions(points);
@torktumlarn1364
@torktumlarn1364 7 жыл бұрын
i had it set to that i just changed it to see if that was it
@MrKrystian010
@MrKrystian010 7 жыл бұрын
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(); } } }
@torktumlarn1364
@torktumlarn1364 7 жыл бұрын
can you just type copy past your hole code here it dosent seem to work for me i dont know why
@MrKrystian010
@MrKrystian010 7 жыл бұрын
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_soulspark
@a_soulspark 7 жыл бұрын
I'd like to be a patron but I have no money :(
@BoardToBitsGames
@BoardToBitsGames 7 жыл бұрын
+Pedro Brito no worries! As long as you're watching and learning something, I'm good!
@MaxStranger7
@MaxStranger7 4 жыл бұрын
It looks like your formula is a bit wrong, doesn't it? en.wikipedia.org/wiki/Parametric_equation
@a_soulspark
@a_soulspark 7 жыл бұрын
"Understandfing Ellipses"?
@BoardToBitsGames
@BoardToBitsGames 7 жыл бұрын
+Pedro Brito its German, I think XD
@jonjimihendrix
@jonjimihendrix 6 жыл бұрын
"We're making video games here, so we can ignore physics." 😃🙃😃
@VR360TV
@VR360TV 4 жыл бұрын
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_
@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.
Orbital Paths in Unity, Part 2: Making an Ellipse Class
12:55
Board To Bits Games
Рет қаралды 18 М.
Coding Adventure: Solar System
12:12
Sebastian Lague
Рет қаралды 869 М.
I made a full GAME in 400 HOURS - this is how - in 19 minutes!
19:00
EASY Stats and Modifiers in Unity | Broker Chain Pattern
16:05
How Two People Created Gaming’s Most Complex Simulation System
38:54
ThatGuyGlen
Рет қаралды 1,5 МЛН
How Games Fake Water
22:52
Acerola
Рет қаралды 225 М.
PID Controllers in Unity3D
16:05
Vazgriz
Рет қаралды 83 М.
How I animate 3Blue1Brown | A Manim demo with Ben Sparks
53:41
3Blue1Brown
Рет қаралды 1,1 МЛН
SCRIPTABLE OBJECTS in Unity
8:57
Brackeys
Рет қаралды 1 МЛН
Unity vs Unreal: Which Engine Should You Choose As A Beginner
14:18
Awesome Tuts - Anyone Can Learn To Make Games
Рет қаралды 995 М.