Creating Planetary Gravity With Lineforces

So I am trying to make a game where the player is attracted to a planet/round mesh. I want the player to be able to walk on it and get in orbit around it using lineforces i have figured out the lineforce but how can i make the orientation of the player math direction relative to the planet?

Here is an example of my goal.

As you can see the player is attracted to the center/center of mass instead of roblox’s usual gravity

I managed to do this already with normal parts but the humanoid makes it stand up so i cant.

Lineforces can get into orbit too but the humanoid has issues because it stands up automatically so players can stand anywhere on the sphere please help.

Is there an efficient way to do this?

Note: I have tried egomooses plugin i don’t want to use it and it doesn’t work in my case either

1 Like

I really don’t think you should make it yourself, I know you stated you don’t want to use egomooses plugin and it doesn’t work for you, but at least try to go to their script and edit it to your liking. Since the script isn’t gonna end up much different from what you make most likely. I don’t usually do this kind of script so at least study egomooses script so you can have an idea of what to do.

Already tried i have eveything set i just need a way to change orientation of the player

Parent a BodyGyro object to your HumanoidRootPart. Using script, every frame create a CFrame that is at your player’s position and looking at the center of the planet.

local DesiredFrame = CFrame.new(pos, lookAt)

Next, get the orientation components of the CFrame you have created:

local x, y, z = DesiredFrame:ToEulerAnglesXYZ ( )

Next, modify the CFrame of the BodyGyro using CFrame.Angles(). Rotate each orientation axis by increments of math.rad(90) to discover the correct orientation of your player.

Gyro.CFrame = CFrame.new(Gyro.Position.Y, Gyro.Position.Y, Gyro.Position.Z) * CFrame.Angles(0,0,0)

I am also doing the same thing as to what the creator of the post is doing, but it’s not working. I don’t know if it’s me or it’s your code.

(Also you can’t get the gyro’s position, only the cframe)

local DesiredFrame = CFrame.new(hrp.Position, planetCenter) -- the center of the planet
local x, y, z = DesiredFrame:ToEulerAnglesXYZ()
			
gyro.CFrame = CFrame.new(hrp.Position.X, hrp.Position.Y, hrp.Position.Z) * CFrame.Angles(0,0,0)
1 Like

Ive made real planetery gravity using nasa equations before, it is completly possible, you will just need to add a rotation to the lookvector to be able to change the lookvecor to the center of the planet.

If you are using pre set gravity values this should be easy enough to achive unlike when I used nasa equations :sweat_smile:

1 Like

Well since I also need help, can you provide the code if possible because I dont know what rotation values i’m trying to get which made me confused.

The humanoid state that is causing ur code to bug is the standing state falling state etc. For example if the humanoidstate was platformstanding the humanoid wouldn’t affect the code.

Why the bump? this is a 2 year old post now, and also that’s not even a solution…