Help with scripting and gravity! ASAP!

Hi, so I watched a Brackeys video(

) about gravity and movement. I need help putting gravity on planets, because I have a cool solar system game concept and I need gravity on my player(which I sort of have) and I need to add gravity to the planets, so I can walk on them.
If you wish to see the scripts I used, I just used the ones from the video. If you want to see the ones I have for some reason, add me on discord: The3EyedGamerYT#7307. If you can, please reply as I really want to finish this game this week(the week of 2/27/2020). Thanks for the help in advance!

I would just google “Unity walking on a sphere”. You’ll find a lot of content on this. Many people have made videos or other stuff on how to direct your player’s “Up” direction away from the surface, and gravity towards the center of the sphere.

Thanks for the idea, but I have tried that. They all give me errors. Have a great day!

If you’re getting an error with some code, show the code (ideally only the relevant excerpt, and using Code tags), and state the specific error. If you just want someone to write your code for you, you can buy things on the asset store. But if you want help here, you’ll usually find you need to show what you’ve got so far, and ask for specific guidance.

1 Like

Ok. Thanks for the help. I am new to Unity and have never coded C# before. That is why I am confused. I just need help with getting gravity to work, maybe a video or something. Thanks again! Have a great day!

It is very not polite to ask others to Hurry up. Most often, such request backfires and you more likely receive unwanted message, or none. If anything related to closing deadline, is your own fault.

What you’re trying to do isn’t super difficult, but it’s also not what I’d generally recommend for someone’s first Unity project. Things to look into and understand:

  • Understand performing a Raycast to determine the angle of the ground in the player’s feet. This is the “normal” direction of the surface.
  • If you’re using physics, use AddForce to push the player in the opposite direction of that Normal vector. That’s essentially all there is to “gravity” on a sphere. It’s more complex if you want the gravity of multiple planets to affect the player simultaneously, but not significantly so.
  • In most cases, you’ll also want to use that Normal vector to change the player’s “Up” direction, so their feet stay on the surface.
1 Like

Sorry about that. I understand what you mean. I will not do it again, I am just a little irritated because I have been working for hours on this game and searching up forums and youtube videos. Once again, sorry about that.

Ok. Thanks! I will do more research and look in to this. Have a great day!

If you never programmed, expect spending weeks and months. Not few hours or days. You need be very patient and persistent.

Another thing is, since you never programmed in C# and Unity, anything we may have suggest here, will be black magic for you.

Besides, you are on wrong forum section. Please look up for getting started forum section and read pinned posts.

Hey there, I just finished watching a few videos on Raycasts and Addforce. Here is my code for player movement: https://pastebin.com/1g5Ef0J9 . I guess I am just a little confused as to how to apply that code into my code for my game. If this means anything or will help at all, here is my mouse looking script: https://pastebin.com/Q1fLMSrZ . Thanks again for helping me with this project!

Ah I see. So sorry for the inconvenience. I will go make a post in there, and thanks for the help! It really means a lot!

Also, one more question. How do I close a thread? Thanks again :stuck_out_tongue:

You can use raport button below the post. Then just write something in line, “request to close thread, because wrong forum section”.

Thanks! Have a great day!

In the future, please request that the topic be moved, rather than closing topics and re-starting them elsewhere.

–Eric

1 Like