Unity Tutorial - Solar System with Unity Physics

Поделиться
HTML-код
  • Опубликовано: 7 ноя 2024

Комментарии • 111

  • @mezan2604
    @mezan2604 2 года назад +6

    Honestly this is the best tutorial about this topic

  • @garcia7953
    @garcia7953 2 года назад +24

    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.

  • @StellarMirage
    @StellarMirage 2 года назад +5

    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.

  • @t2g4_channel
    @t2g4_channel Год назад +4

    Whoah, this is awesome!
    Thank you! Super video, it is short, explaining a lot, and have clear demostration!

  • @ComplexKangaroo
    @ComplexKangaroo Год назад +3

    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.

  • @LordxGx07
    @LordxGx07 Год назад +1

    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...

  • @smoothblock7009
    @smoothblock7009 2 года назад +3

    hi , nice video but i have a question - when using urp my textures dont apply to my object. any solution please??

  • @tracksuitcheems
    @tracksuitcheems Год назад +4

    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.

  • @ytubeanon
    @ytubeanon 3 года назад +2

    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 года назад +7

    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 года назад +2

      Spotted it too, I've pinned a comment with the correction.

  • @ouuuaburger2093
    @ouuuaburger2093 Год назад +1

    Do you think blender is better than Unity in rendering solar system?

  • @tntram2834
    @tntram2834 2 года назад +1

    Very useful video!
    It would be interesting to see what could be done from this project

  • @CheesyMez
    @CheesyMez 2 месяца назад

    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.

  • @havendewart
    @havendewart 2 года назад +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!

  • @sujalvc
    @sujalvc 3 года назад +2

    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 года назад +1

      It should be possible in combination with the particle system.

  • @Maxvellua
    @Maxvellua Год назад +1

    Thank you for the video!

  • @thedarkshadoww9711
    @thedarkshadoww9711 2 года назад +1

    Ty so much for the tutorial, helps a lot

  • @taxtherich194
    @taxtherich194 Год назад +1

    thank you for this great tutorial.. merci

  • @hue7075
    @hue7075 2 года назад +1

    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.

  • @HaveDraw
    @HaveDraw Год назад +1

    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.

  • @divac3042
    @divac3042 2 года назад +1

    It's so cool! Thank you very much!

  • @rohithkumar2576
    @rohithkumar2576 Год назад +1

    Is there any way to download the assets directly? Someone please reply

  • @liliansananikone3588
    @liliansananikone3588 Год назад +1

    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).

  • @jeronimocollares320
    @jeronimocollares320 2 года назад +1

    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 года назад +1

      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 года назад +1

      @@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).

  • @Keith-8h1a2b9i
    @Keith-8h1a2b9i Месяц назад

    is this used only for circular orbits, or can it make elliptical too?

  • @mukapochotordo649
    @mukapochotordo649 2 года назад +3

    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!

  • @alvaropazmino672
    @alvaropazmino672 Год назад +1

    WOWOWOWOW!

  • @choc3732
    @choc3732 2 года назад +1

    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 года назад +1

      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.

  • @Avariths
    @Avariths 2 года назад +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  2 года назад

      Did you add mass to the sun?

    • @Avariths
      @Avariths 2 года назад

      @@coderious4568 yes. I put the mass of the sun at 333000 and the earth at 1. Gravity of both planets turned off

    • @coderious4568
      @coderious4568  2 года назад

      @@Avariths Did you add the tag to the celestials?

    • @Avariths
      @Avariths 2 года назад

      @@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 года назад +1

      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 9 месяцев назад

    I`m trying to create a deformable 3D space time grid in unity. How should I approach it?

  • @pikachuiswatchingu601
    @pikachuiswatchingu601 2 года назад +3

    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 года назад +2

      Checking the IsKinematic checkbox in the sun Rigidbody will not apply physics on the object.

  • @tamargamer4667
    @tamargamer4667 Год назад +1

    Where can i find a 3d models like These planets and the sun are wonderful

    • @coderious4568
      @coderious4568  Год назад +1

      Thanks, I made a tutorial on how to create the Sun. Planet textures can be found on the NASA website and are public domain.

  • @R2_Audio_
    @R2_Audio_ 2 года назад +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

  • @brotkrumeleintopf7749
    @brotkrumeleintopf7749 Год назад +1

    5:07 but your sun is moving away from the center?!

  • @Gaisiran
    @Gaisiran 3 месяца назад

    Excellent!

  • @coderious4568
    @coderious4568  3 года назад +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 года назад +1

      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.

  • @damarkuncoro
    @damarkuncoro Год назад +1

    i love it

  • @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.

  • @JohananStarGiver
    @JohananStarGiver 9 месяцев назад

    How did you make that beatifull sun? i cant find a way to make it this beatifull :(

  • @mjc7747
    @mjc7747 2 года назад +1

    Thank you soooo much!!

  • @myfishisnothappy1595
    @myfishisnothappy1595 2 года назад +1

    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 года назад +1

      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.

  • @fatimaarif5944
    @fatimaarif5944 2 года назад +1

    thanks life saver. < 3

  • @snipeax0478
    @snipeax0478 2 года назад +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?

  • @abdelrahmanqe-5538
    @abdelrahmanqe-5538 8 месяцев назад

    Very Useful Vid

  • @baskanaqua
    @baskanaqua Год назад +3

    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 Год назад +1

      @@coderious4568 i need to thank u!!! SO SOOO thank u so muchh ur so good

  • @JakubKas
    @JakubKas 2 года назад

    I get " operator '.' cannot be applied to operand of type 'void' " error message :/

  • @Baconmaster-ls4wf
    @Baconmaster-ls4wf 6 месяцев назад

    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  6 месяцев назад

      The project is available on GitHub link under the video if you want to compare your solution to the example.

  • @gavynmcdonald8739
    @gavynmcdonald8739 2 года назад +5

    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 года назад +3

      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!

  • @TheRunningSongs
    @TheRunningSongs 3 года назад +1

    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

  • @thegamedevstudent
    @thegamedevstudent 2 года назад +1

    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 года назад +1

    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?

  • @myfishisnothappy1595
    @myfishisnothappy1595 2 года назад

    I luv you.

  • @KassidyJMoore
    @KassidyJMoore Год назад

    I can't get the moon to orbit the planet

  • @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);
    }