Unity Tutorial - Solar System with Unity Physics

  Рет қаралды 45,500

Coderious

Coderious

Күн бұрын

Пікірлер: 111
@mezan2604
@mezan2604 2 жыл бұрын
Honestly this is the best tutorial about this topic
@garcia7953
@garcia7953 2 жыл бұрын
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.
@coderious4568
@coderious4568 2 жыл бұрын
Thank you so much it means a lot!
@StellarMirage
@StellarMirage 3 жыл бұрын
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.
@coderious4568
@coderious4568 3 жыл бұрын
congrats!
@t2g4_channel
@t2g4_channel Жыл бұрын
Whoah, this is awesome! Thank you! Super video, it is short, explaining a lot, and have clear demostration!
@LordxGx07
@LordxGx07 Жыл бұрын
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...
@ytubeanon
@ytubeanon 3 жыл бұрын
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
@coderious4568
@coderious4568 3 жыл бұрын
Excellent, thank you for the tip!
@Enderia2
@Enderia2 Жыл бұрын
@@coderious4568t’s actually just f
@williamwall1785
@williamwall1785 2 жыл бұрын
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.
@coderious4568
@coderious4568 2 жыл бұрын
Spotted it too, I've pinned a comment with the correction.
@rohithkumar2576
@rohithkumar2576 Жыл бұрын
Is there any way to download the assets directly? Someone please reply
@coderious4568
@coderious4568 3 жыл бұрын
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).
@misa8286
@misa8286 3 жыл бұрын
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?
@coderious4568
@coderious4568 3 жыл бұрын
@@misa8286 there a link to Discord in the channel description, feel free to contact me over there
@bensawiuk7094
@bensawiuk7094 2 жыл бұрын
@@coderious4568 im having the same problem, where do i contact you
@coderious4568
@coderious4568 2 жыл бұрын
@@bensawiuk7094 There is a Discord link on my page description
@coderious4568
@coderious4568 2 жыл бұрын
@@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.
@HaveDraw
@HaveDraw Жыл бұрын
What if i dont have the transform.right, how could i do the same thing?
@coderious4568
@coderious4568 Жыл бұрын
How could you not have transform.right? All GameObjects have a transform.
@tntram2834
@tntram2834 2 жыл бұрын
Very useful video! It would be interesting to see what could be done from this project
@smoothblock7009
@smoothblock7009 2 жыл бұрын
hi , nice video but i have a question - when using urp my textures dont apply to my object. any solution please??
@ComplexKangaroo
@ComplexKangaroo Жыл бұрын
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.
@thedarkshadoww9711
@thedarkshadoww9711 2 жыл бұрын
Ty so much for the tutorial, helps a lot
@havendewart
@havendewart 2 жыл бұрын
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.
@gilleswalther5964
@gilleswalther5964 2 жыл бұрын
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.
@havendewart
@havendewart 2 жыл бұрын
Thanks!
@divac3042
@divac3042 2 жыл бұрын
It's so cool! Thank you very much!
@Maxvellua
@Maxvellua 2 жыл бұрын
Thank you for the video!
@ouuuaburger2093
@ouuuaburger2093 Жыл бұрын
Do you think blender is better than Unity in rendering solar system?
@brotkrumeleintopf7749
@brotkrumeleintopf7749 Жыл бұрын
5:07 but your sun is moving away from the center?!
@taxtherich194
@taxtherich194 Жыл бұрын
thank you for this great tutorial.. merci
@tracksuitcheems
@tracksuitcheems 2 жыл бұрын
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.
@Avariths
@Avariths 3 жыл бұрын
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
@coderious4568 3 жыл бұрын
Did you add mass to the sun?
@Avariths
@Avariths 3 жыл бұрын
@@coderious4568 yes. I put the mass of the sun at 333000 and the earth at 1. Gravity of both planets turned off
@coderious4568
@coderious4568 3 жыл бұрын
@@Avariths Did you add the tag to the celestials?
@Avariths
@Avariths 3 жыл бұрын
@@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
@bennettpoh
@bennettpoh 2 жыл бұрын
Did you apply the script to the planet itself? If so, you have to create an empty GameObject and assign the script there.
@patrudoizero
@patrudoizero 10 ай бұрын
I`m trying to create a deformable 3D space time grid in unity. How should I approach it?
@pikachuiswatchingu601
@pikachuiswatchingu601 2 жыл бұрын
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
@coderious4568
@coderious4568 2 жыл бұрын
Checking the IsKinematic checkbox in the sun Rigidbody will not apply physics on the object.
@mukapochotordo649
@mukapochotordo649 2 жыл бұрын
Hi, could you make a tutorial to make the orbit in the shape of an ellipse? Very good tutorial by the way.
@coderious4568
@coderious4568 2 жыл бұрын
The the formula for an ellipse is pinned in the comments. Thanks 👍
@mukapochotordo649
@mukapochotordo649 2 жыл бұрын
@@coderious4568 ty so much!
@liliansananikone3588
@liliansananikone3588 Жыл бұрын
In realtime, is the G float member different for each celestial ?
@liliansananikone3588
@liliansananikone3588 Жыл бұрын
I did the same way with all celestials of your spreadsheet but some celestials end to collide (Sun, Mercury and Earth).
@tamargamer4667
@tamargamer4667 Жыл бұрын
Where can i find a 3d models like These planets and the sun are wonderful
@coderious4568
@coderious4568 Жыл бұрын
Thanks, I made a tutorial on how to create the Sun. Planet textures can be found on the NASA website and are public domain.
@snipeax0478
@snipeax0478 2 жыл бұрын
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?
@JakubKas
@JakubKas 2 жыл бұрын
I get " operator '.' cannot be applied to operand of type 'void' " error message :/
@CheesyMez
@CheesyMez 3 ай бұрын
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.
@overangelixvod1406
@overangelixvod1406 Жыл бұрын
Hello, I want to make a solar System but I understant why do you increased the earth mass by 15 ?
@coderious4568
@coderious4568 Жыл бұрын
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.
@hue7075
@hue7075 2 жыл бұрын
Awesome stuff, how can I make the planet movements significantly slower but still make it work? new to coding sorry lol
@coderious4568
@coderious4568 2 жыл бұрын
The speed can be adjusted with the G variable.
@TheRunningSongs
@TheRunningSongs 3 жыл бұрын
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
@coderious4568
@coderious4568 3 жыл бұрын
What code editor do you use?
@TheRunningSongs
@TheRunningSongs 3 жыл бұрын
@@coderious4568 Visual code studio, same as you
@coderious4568
@coderious4568 3 жыл бұрын
@@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.
@TheRunningSongs
@TheRunningSongs 3 жыл бұрын
@@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 :)
@coderious4568
@coderious4568 3 жыл бұрын
@@TheRunningSongs discord.gg/KsgpVVYcj9 updated
@myfishisnothappy1595
@myfishisnothappy1595 2 жыл бұрын
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...
@coderious4568
@coderious4568 2 жыл бұрын
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.
@jeronimocollares320
@jeronimocollares320 2 жыл бұрын
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)?
@coderious4568
@coderious4568 2 жыл бұрын
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.
@jeronimocollares320
@jeronimocollares320 2 жыл бұрын
​@@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. :)
@coderious4568
@coderious4568 2 жыл бұрын
@@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.
@jeronimocollares320
@jeronimocollares320 2 жыл бұрын
@@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).
@sujalvc
@sujalvc 3 жыл бұрын
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.
@coderious4568
@coderious4568 3 жыл бұрын
It should be possible in combination with the particle system.
@Baconmaster-ls4wf
@Baconmaster-ls4wf 8 ай бұрын
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
@coderious4568
@coderious4568 8 ай бұрын
The project is available on GitHub link under the video if you want to compare your solution to the example.
@choc3732
@choc3732 2 жыл бұрын
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
@coderious4568 2 жыл бұрын
r = distance between orbiting bodies a = length of the semi major axis
@choc3732
@choc3732 2 жыл бұрын
@@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.
@R2_Audio_
@R2_Audio_ 2 жыл бұрын
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?
@coderious4568
@coderious4568 2 жыл бұрын
Masses and distances can be found on google quite easily
@JohananStarGiver
@JohananStarGiver 10 ай бұрын
How did you make that beatifull sun? i cant find a way to make it this beatifull :(
@Keith-8h1a2b9i
@Keith-8h1a2b9i 2 ай бұрын
is this used only for circular orbits, or can it make elliptical too?
@gilleswalther5964
@gilleswalther5964 2 ай бұрын
Works with elliptical orbits
@baskanaqua
@baskanaqua 2 жыл бұрын
ur code working so good uhm how can i ask.. can i use this my education project?
@coderious4568
@coderious4568 2 жыл бұрын
Yes you can use it
@baskanaqua
@baskanaqua 2 жыл бұрын
@@coderious4568 i need to thank u!!! SO SOOO thank u so muchh ur so good
@Gaisiran
@Gaisiran 4 ай бұрын
Excellent!
@alvaropazmino672
@alvaropazmino672 Жыл бұрын
WOWOWOWOW!
@mjc7747
@mjc7747 2 жыл бұрын
Thank you soooo much!!
@damarkuncoro
@damarkuncoro Жыл бұрын
i love it
@yaxalo
@yaxalo 2 жыл бұрын
I dont know if this is just me but my planets like to go out of orbit and shoot off into space.
@coderious4568
@coderious4568 2 жыл бұрын
The script must be attached to one GameObject in the project not all planets. That might be the cause.
@R2_Audio_
@R2_Audio_ 2 жыл бұрын
@@coderious4568 hi, i have the same issue can you help?
@DrDandD
@DrDandD 2 жыл бұрын
​@@R2_Audio_ have you tried what Coderious said above.
@cfg4522
@cfg4522 2 жыл бұрын
Make sure that InitialVelocity function is being called in the Start method and not in FixedUpdate
@chiefynuts
@chiefynuts Жыл бұрын
@@coderious4568 works perfectly. was confused for so long.thank you!
@abdelrahmanqe-5538
@abdelrahmanqe-5538 9 ай бұрын
Very Useful Vid
@fatimaarif5944
@fatimaarif5944 2 жыл бұрын
thanks life saver. < 3
@thegamedevstudent
@thegamedevstudent 2 жыл бұрын
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
@coderious4568
@coderious4568 2 жыл бұрын
Have you double checked the mass of your objects?
@thegamedevstudent
@thegamedevstudent 2 жыл бұрын
@@coderious4568 yes, the sun has mass of 333000 while the planet has mass of 1, still the problem is occurring
@coderious4568
@coderious4568 2 жыл бұрын
@@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
@RiversJ
@RiversJ 2 жыл бұрын
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?
@KassidyJMoore
@KassidyJMoore Жыл бұрын
I can't get the moon to orbit the planet
@myfishisnothappy1595
@myfishisnothappy1595 2 жыл бұрын
I luv you.
@sanyohamarr8285
@sanyohamarr8285 Жыл бұрын
As expected, it doesn't work. Oh well, another tutorial fail.
@Brainyplanet
@Brainyplanet Жыл бұрын
It worked for me, maybe you missed something
@Excelsiur1
@Excelsiur1 Жыл бұрын
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.
@gizmo95
@gizmo95 Жыл бұрын
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); }
Coding Adventure: Solar System
12:12
Sebastian Lague
Рет қаралды 869 М.
Recreating No Man Sky without Coding in Unity
9:18
MadFinn13
Рет қаралды 19 М.
How many people are in the changing room? #devil #lilith #funny #shorts
00:39
小丑教训坏蛋 #小丑 #天使 #shorts
00:49
好人小丑
Рет қаралды 37 МЛН
How Many Balloons To Make A Store Fly?
00:22
MrBeast
Рет қаралды 195 МЛН
Интересно, какой он был в молодости
01:00
БЕЗУМНЫЙ СПОРТ
Рет қаралды 3,9 МЛН
I Wish I Had Known This Before I Started Unity Game Development...
11:11
Unity Tutorial - Make a STAR in Shader Graph
4:43
Coderious
Рет қаралды 21 М.
Orbital Paths in Unity, Part 3: Making a Planet Orbit
19:53
Board To Bits Games
Рет қаралды 52 М.
Understand Unity Rotation in 5 minutes
5:23
CodeForge
Рет қаралды 20 М.
EPIC GLOW IN UNITY 2020.2
5:13
Clipper
Рет қаралды 73 М.
How Games Fake Water
22:52
Acerola
Рет қаралды 225 М.
Coding Adventure: Boids
8:35
Sebastian Lague
Рет қаралды 1,6 МЛН
I Made an Electronic Chessboard Without Turns
14:32
From Scratch
Рет қаралды 951 М.
Orbit Paths in Unity: Understanding Ellipses
13:23
Board To Bits Games
Рет қаралды 34 М.
I'm Coding an Entire Physics Engine from Scratch
9:19
Gonkee
Рет қаралды 1,7 МЛН
How many people are in the changing room? #devil #lilith #funny #shorts
00:39