Why is your channel so small? Great content! You deserve so many subscribers, i can understand something so complex in just some minutes, that is amazing! Congratulations.
I knew the formuals and everything but wasn’t ready to implement it but after seeing your video I got the faith in myself to implement it and now I have my own solar system.
Excellent tutorial, thanks! I got it working in Unity 2021.3.24f1 but my code is identical to yours and all the RigidBody mass settings and I turned off "use gravity" as you did, but the Earth takes off on a long comet like orbit. I had to multiply the initial velocity by 0.7 to get a perfect circle, which is weird. I just realized 0.7 is 1/sqrt(2), and indeed adding 2*r solved it and makes it work, but your code didn't have that and your code matches Wikipedia. Weird. Thanks for all the other cool tricks with TrailRenderer and speeding up project time.
A beautiful simulation with physics formula on Unity, beautiful ! I'll reproduce your code I guess. And after that, I'd like to add code to simulate planetary rings (or proto-solar disc, or accretion discs), like Saturne, Jupiter...
Greetings. I followed your tutorial for the shader graph star and this one for the orbits. However, my planets are not dynamically lit. Could you do a video on lighting in Unity or recommend any good ones. Soulcraft looks good, btw. Hope to see it released soon. Thanks.
quick tip - I think if you press Shift+F it will lock on to your selected gameobject in Scene view, so you don't have to manually scroll the screen with your mouse
Cool stuff! However, there is an error in the formula for velocity in an elliptical orbit. The (2/r + 1/a) should be (2/r - 1/a). Also, on the distance scale chosen, the earth and the sun would be fifty times smaller.
thanks for such a good tutorial! would you know how to have the trajectory of an object ahead of time, rather than trailing behind the objects like in kerbal space program for example.
Just wondering why did you add two foreach loops. I am sure there is a good reason, but I just cant figure it out and I am trying to learn C# so was curious.
Nice tutorial, really thanks. But you have something about a 'HUGE' system star, Solar or, at last, what is the best way to do it without broke the engine (because this size of a space, planets, etc)?
Hi, thanks for your comment. To make a huge system I would look into Compute Shader and ECS/DOTS. The two options are completely different but both allow to perform a ton of operations per second. I made a tutorial on how to use the compute shader, it might be suitable for what you have in mind. With ECS/DOTS Unity can manage thousands of different objects at the same time with much better performance than using the GameObject/Monobehavior framework. it is still a preview package though.
@@coderious4568 Thanks for answering. I'm working with a 'middle ground' on the 'huge' theme. Instead of thinking in terms of 'huge', use tricks like scaling something down to avoid rendering and performance issues. There will be many steps, I'm still a novice - I know nothing about DOTS, I would like ideas, even. Now I focus on movement, like having a spacecraft, for example, flying in 'cruise flight' with this spacecraft being small and simulating that flight as something very slow and maintaining a good 'frame by frame' quality? That's my challenge, learn that. A smaller Universe, with small objects, pretending to be big. Another thing I've been looking for is light, like a general lens flare in this universe and combine it with this Sun used in your example. I know it's newbie stuff, I apologize - but that's how we learn. :)
@@jeronimocollares320 To render big lands, procedural generation could help as well. I made a video about it. The concept is in 2D, but it's totally applicable to 3D as well.
@@coderious4568 my idea is simple (as a new) its a space game using point and click - literally, like Eve Online in your BASIC aspect (for now, strict to two goals. Size of a sector in the Universe (objects included) and movement (here it goes from the movement of objects navigating in a three-dimensional space to that of the camera).
Hey man, I have gotten it to work with the circular orbit! However for the elliptical it's not working. Seeing as this solar system is scaled down, what values do I need to use for the values: 2, 1, a in this part of the equation -> (2/r - 1/a)?
@@coderious4568 Thanks man. Do you know what factor I have to scale down the “a” value by? The actual value for a is about 100,000,000km. I’m not sure how to scale it down to suit this smaller solar system.
So I have a weird problem with the velocity. When I add the velocity part to the script my earth just flies away. I copied the script line for line. Any idea why this is happening to me?
@@coderious4568 I gave the tag Celestial to the sun and Earth. The gravity part of the script functions as intended. The sun also starts to move away from the Earth when the velocity component is added along with the earth shooting away
hi this was a wonderful tutorial but im having a problem where after i added more planets the sun started to wander. like it wanders in a straight line and pretty fast too. i get that it gets pulled a little by the other planets but it's literally wandering to a whole nother galaxy
There is an error in the slide at 3:46, the elliptic orbit speed is the square root of G * m2 * (2/r - 1/a) where a is for the alpha in the formula. It is the length of the semi-major axis of the elliptical orbit (not a the game object).
This doesn't work for me this fix. it says "Operator '/' cannot be applied to operands of type 'int' and 'GameObject'" how do i fix this? and can i contact you?
@@misa8286 I added a clarification. "a" is the for the Greek letter alpha in the formula, not for GameObject a from the foreach loop. The alpha is the semimajor axis of its orbit.
It's to make it work with the scale of the planet. To make it look better the distance and sizes of the planets are modified, so the mass needs to be adjusted as well.
could you project shadows and add a fixed pov from earth surface? Even without earth rotation on its axis, to see the Moon phases? That would be amazing...
thank you, that helped me so much to figure some problem with my project, would it be possible to make a video on how to predict the trajectory of a planet with a linerender or something?
@@coderious4568 Hello, Thanks fir the response, when i jooin the discord server it says invite invalid. If you could update the invite that would be great, thanks :)
@@thegamedevstudent double check the inputs, make sure gravity is off the rigibodies, that it is not kinematic and that the Celestial tag was added. Then use the debugger to check what is wrong :-) Good luck
It seems like the initial velocity makes the sun drift! I added a simple if statement to check if it's the sun. this seemed to fix it.. although a bit of a hack! if(a.name != 'sun'){ a.GetComponent().velocity += a.transform.right * Mathf.Sqrt((G * m2) /r); }
Honestly this is the best tutorial about this topic
Why is your channel so small?
Great content!
You deserve so many subscribers, i can understand something so complex in just some minutes, that is amazing!
Congratulations.
Thank you so much it means a lot!
I knew the formuals and everything but wasn’t ready to implement it but after seeing your video I got the faith in myself to implement it and now I have my own solar system.
congrats!
Whoah, this is awesome!
Thank you! Super video, it is short, explaining a lot, and have clear demostration!
Excellent tutorial, thanks! I got it working in Unity 2021.3.24f1 but my code is identical to yours and all the RigidBody mass settings and I turned off "use gravity" as you did, but the Earth takes off on a long comet like orbit. I had to multiply the initial velocity by 0.7 to get a perfect circle, which is weird. I just realized 0.7 is 1/sqrt(2), and indeed adding 2*r solved it and makes it work, but your code didn't have that and your code matches Wikipedia. Weird. Thanks for all the other cool tricks with TrailRenderer and speeding up project time.
A beautiful simulation with physics formula on Unity, beautiful !
I'll reproduce your code I guess. And after that, I'd like to add code to simulate planetary rings (or proto-solar disc, or accretion discs), like Saturne, Jupiter...
hi , nice video but i have a question - when using urp my textures dont apply to my object. any solution please??
Greetings. I followed your tutorial for the shader graph star and this one for the orbits. However, my planets are not dynamically lit. Could you do a video on lighting in Unity or recommend any good ones. Soulcraft looks good, btw. Hope to see it released soon. Thanks.
quick tip - I think if you press Shift+F it will lock on to your selected gameobject in Scene view, so you don't have to manually scroll the screen with your mouse
Excellent, thank you for the tip!
@@coderious4568t’s actually just f
Cool stuff! However, there is an error in the formula for velocity in an elliptical orbit. The (2/r + 1/a) should be (2/r - 1/a). Also, on the distance scale chosen, the earth and the sun would be fifty times smaller.
Spotted it too, I've pinned a comment with the correction.
Do you think blender is better than Unity in rendering solar system?
Very useful video!
It would be interesting to see what could be done from this project
thanks for such a good tutorial!
would you know how to have the trajectory of an object ahead of time, rather than trailing behind the objects
like in kerbal space program for example.
Just wondering why did you add two foreach loops. I am sure there is a good reason, but I just cant figure it out and I am trying to learn C# so was curious.
Because gravity goes both ways, A is "attracted" by B and B is "attracted" by A. With the double loop both ways can be captured.
Thanks!
Nice video.
Is deformation of planet w.r.t the nearest Celestial possible?
Like if a planet goes near the sun, it will deform and vapourise.
It should be possible in combination with the particle system.
Thank you for the video!
Ty so much for the tutorial, helps a lot
thank you for this great tutorial.. merci
Awesome stuff, how can I make the planet movements significantly slower but still make it work? new to coding sorry lol
The speed can be adjusted with the G variable.
What if i dont have the transform.right, how could i do the same thing?
How could you not have transform.right? All GameObjects have a transform.
It's so cool! Thank you very much!
Is there any way to download the assets directly? Someone please reply
In realtime, is the G float member different for each celestial ?
I did the same way with all celestials of your spreadsheet but some celestials end to collide (Sun, Mercury and Earth).
Nice tutorial, really thanks. But you have something about a 'HUGE' system star, Solar or, at last, what is the best way to do it without broke the engine (because this size of a space, planets, etc)?
Hi, thanks for your comment. To make a huge system I would look into Compute Shader and ECS/DOTS. The two options are completely different but both allow to perform a ton of operations per second. I made a tutorial on how to use the compute shader, it might be suitable for what you have in mind. With ECS/DOTS Unity can manage thousands of different objects at the same time with much better performance than using the GameObject/Monobehavior framework. it is still a preview package though.
@@coderious4568 Thanks for answering. I'm working with a 'middle ground' on the 'huge' theme. Instead of thinking in terms of 'huge', use tricks like scaling something down to avoid rendering and performance issues. There will be many steps, I'm still a novice - I know nothing about DOTS, I would like ideas, even. Now I focus on movement, like having a spacecraft, for example, flying in 'cruise flight' with this spacecraft being small and simulating that flight as something very slow and maintaining a good 'frame by frame' quality? That's my challenge, learn that. A smaller Universe, with small objects, pretending to be big. Another thing I've been looking for is light, like a general lens flare in this universe and combine it with this Sun used in your example. I know it's newbie stuff, I apologize - but that's how we learn. :)
@@jeronimocollares320 To render big lands, procedural generation could help as well. I made a video about it. The concept is in 2D, but it's totally applicable to 3D as well.
@@coderious4568 my idea is simple (as a new) its a space game using point and click - literally, like Eve Online in your BASIC aspect (for now, strict to two goals. Size of a sector in the Universe (objects included) and movement (here it goes from the movement of objects navigating in a three-dimensional space to that of the camera).
is this used only for circular orbits, or can it make elliptical too?
Works with elliptical orbits
Hi, could you make a tutorial to make the orbit in the shape of an ellipse? Very good tutorial by the way.
The the formula for an ellipse is pinned in the comments. Thanks 👍
@@coderious4568 ty so much!
WOWOWOWOW!
Hey man, I have gotten it to work with the circular orbit! However for the elliptical it's not working. Seeing as this solar system is scaled down, what values do I need to use for the values: 2, 1, a in this part of the equation -> (2/r - 1/a)?
r = distance between orbiting bodies
a = length of the semi major axis
@@coderious4568 Thanks man. Do you know what factor I have to scale down the “a” value by? The actual value for a is about 100,000,000km. I’m not sure how to scale it down to suit this smaller solar system.
So I have a weird problem with the velocity. When I add the velocity part to the script my earth just flies away. I copied the script line for line. Any idea why this is happening to me?
Did you add mass to the sun?
@@coderious4568 yes. I put the mass of the sun at 333000 and the earth at 1. Gravity of both planets turned off
@@Avariths Did you add the tag to the celestials?
@@coderious4568 I gave the tag Celestial to the sun and Earth. The gravity part of the script functions as intended. The sun also starts to move away from the Earth when the velocity component is added along with the earth shooting away
Did you apply the script to the planet itself? If so, you have to create an empty GameObject and assign the script there.
I`m trying to create a deformable 3D space time grid in unity. How should I approach it?
hi this was a wonderful tutorial but im having a problem where after i added more planets the sun started to wander. like it wanders in a straight line and pretty fast too. i get that it gets pulled a little by the other planets but it's literally wandering to a whole nother galaxy
Checking the IsKinematic checkbox in the sun Rigidbody will not apply physics on the object.
Where can i find a 3d models like These planets and the sun are wonderful
Thanks, I made a tutorial on how to create the Sun. Planet textures can be found on the NASA website and are public domain.
hi! this is a awesome tutorial, im making my own solar system simulation too, can i get the codes and the mass tables from somewhere?
Masses and distances can be found on google quite easily
5:07 but your sun is moving away from the center?!
Excellent!
There is an error in the slide at 3:46, the elliptic orbit speed is the square root of G * m2 * (2/r - 1/a) where a is for the alpha in the formula. It is the length of the semi-major axis of the elliptical orbit (not a the game object).
This doesn't work for me this fix. it says "Operator '/' cannot be applied to operands of type 'int' and 'GameObject'"
how do i fix this? and can i contact you?
@@misa8286 there a link to Discord in the channel description, feel free to contact me over there
@@coderious4568 im having the same problem, where do i contact you
@@bensawiuk7094 There is a Discord link on my page description
@@misa8286 I added a clarification. "a" is the for the Greek letter alpha in the formula, not for GameObject a from the foreach loop. The alpha is the semimajor axis of its orbit.
i love it
Hello, I want to make a solar System but I understant why do you increased the earth mass by 15 ?
It's to make it work with the scale of the planet. To make it look better the distance and sizes of the planets are modified, so the mass needs to be adjusted as well.
How did you make that beatifull sun? i cant find a way to make it this beatifull :(
Thank you soooo much!!
could you project shadows and add a fixed pov from earth surface? Even without earth rotation on its axis, to see the Moon phases? That would be amazing...
Add a point light to your sun and it will cast shadows. URP does not support real-time shadow from point lights, but HDRP does.
thanks life saver. < 3
thank you, that helped me so much to figure some problem with my project, would it be possible to make a video on how to predict the trajectory of a planet with a linerender or something?
Very Useful Vid
ur code working so good uhm how can i ask.. can i use this my education project?
Yes you can use it
@@coderious4568 i need to thank u!!! SO SOOO thank u so muchh ur so good
I get " operator '.' cannot be applied to operand of type 'void' " error message :/
Anyone able to help I have implemented this but the planets do not revolve around the sun they just start going all over the place
The project is available on GitHub link under the video if you want to compare your solution to the example.
I dont know if this is just me but my planets like to go out of orbit and shoot off into space.
The script must be attached to one GameObject in the project not all planets. That might be the cause.
@@coderious4568 hi, i have the same issue can you help?
@@R2_Audio_ have you tried what Coderious said above.
Make sure that InitialVelocity function is being called in the Start method and not in FixedUpdate
@@coderious4568 works perfectly. was confused for so long.thank you!
I followed the gravity script but when i compile the script i get two errors saying ';' and '{' I double checked everything and nothing is working
What code editor do you use?
@@coderious4568 Visual code studio, same as you
@@TheRunningSongs You can reach out on the Discord channel and post your code. There is a link to the Discord on the description of my page.
@@coderious4568 Hello, Thanks fir the response, when i jooin the discord server it says invite invalid. If you could update the invite that would be great, thanks :)
@@TheRunningSongs discord.gg/KsgpVVYcj9 updated
instead of the planet moving towards the sun, the sun is moving towards the planet in the gravity part. cud u pls lend a hand
Have you double checked the mass of your objects?
@@coderious4568 yes, the sun has mass of 333000 while the planet has mass of 1, still the problem is occurring
@@thegamedevstudent double check the inputs, make sure gravity is off the rigibodies, that it is not kinematic and that the Celestial tag was added. Then use the debugger to check what is wrong :-) Good luck
Err i don't mean to be pedantic but i don't see Unity Physics being used here and i'm presuming this is using the built-in Physx physics engine?
I luv you.
I can't get the moon to orbit the planet
As expected, it doesn't work. Oh well, another tutorial fail.
It worked for me, maybe you missed something
This worked perfectly for me as well. Go step-by-step and double check all of your settings and values. Seems to be working for everybody else.
It seems like the initial velocity makes the sun drift! I added a simple if statement to check if it's the sun. this seemed to fix it.. although a bit of a hack!
if(a.name != 'sun'){
a.GetComponent().velocity += a.transform.right * Mathf.Sqrt((G * m2) /r);
}