Local gravity system

Now while I pride myself on my ability to figure out scripting problems myself, I have to accept defeat on this one.

I’m currently making a game where the setting is in space. When you go outside the gravity should be different, ( gravity value being 100) but no matter what I tried it changed the gravity sever wide for everyone.

So in short I need help making a local gravity system.

Edit: I tried local scripts but couldn’t quite figure out the code for it.

1 Like

could you be more specific? This might help with your problem:

1 Like

This is very generic, please be more specific of what solutions you have attempted since it may help us construct a more individual solution since we get a wider view of how you wish the system to work as well as a basis to expand ideas off.

Given the limited context, I’ll give a broad answer.

Change the Workspace.Gravity property using a Localscript, and make that change dependent of where the player is.

Some ways to do that include:

  • Region3’s and check the players current region.
  • Giant parts with .Touched signals connection.
  • Raycasting to check if the player is inside a building.

Article related to the above mentioned:

I suggest using Raycasting since it would be trivial to just constantly raycast upwards to defect if the player is no longer under something, but use whatever you feel fits best.

A related question (instead about changing the music in the given area, but same concept could be applied: Music in certain areas)

2 Likes

Changing gravity itself won’t help much since the player will still have a sense of direction (up and down), scripting a custom camera may be necessary. You could use body forces instead of changing the value of gravity.

More on body forces BodyForce | Documentation - Roblox Creator Hub

Here are some useful links which may also be relevant:

Workspace | Documentation - Roblox Creator Hub
https://scriptinghelpers.org/questions/75683/is-there-a-way-to-activate-no-gravity-that-is-local-to-the-player
https://scriptinghelpers.org/questions/50188/is-it-possible-to-change-the-directional-pull-of-gravity-in-roblox
https://scriptinghelpers.org/questions/7906/how-do-i-make-a-brick-with-no-gravity

A game I found which I believe is a great example of what you’re trying to achieve is [EGG HUNT] Innovation Inc. Spaceship - Roblox

1 Like

We really need more information about what you are trying to solve. Does gravity need to be in different directions at different places (say like on a planet or near a star)? Obviously the strength needs to change depending on where the user is, but is in only on / off or in specific regions? Will it continuously change based on distance, again like on a planet?

I’ve had good experiences with LineForce objects which have a InverseSquareLaw property which allows the Roblox physics engine to handle calculating the changing force magnitude based on distance. It also allows you to calculate gravity to multiple objects.

Thank you everyone for your help I got it working!

1 Like