Running around a sphere

I’m trying to make my character round a sphere. Full disclosure - I didn’t expect this to work, but I thought it would get me closer!

I currently have my character ignoring world gravity, and falling towards the centre of the sphere. It only responds to these forces in states such as jumping though, and isn’t oriented with feet towards the moon.

image

I have a moon (ball part) and a spawn point in the workspace. I have a script and a couple of body movers in StarterCharacterScripts (which I move to HumanoidRootPart one the character is loaded in). This is my script (CharacterSetup)

local character = script.Parent

local bodies = {"Model", "Hat", "Accessory"}
local ignore = {"BodyColors", "Humanoid", "Script", "RocketPropulsion", "BodyForce", "LocalScript"}
function weigh(instance, mass)
	mass = mass or 0
	
	for _,obj in pairs(instance:GetChildren()) do
		if table.find(bodies, obj.ClassName) then
			mass = mass + weigh(obj)
		elseif obj:IsA("BasePart") then
			mass = mass+obj:GetMass()
		elseif not table.find(ignore, obj.ClassName) then
			warn("unknown class type: "..obj.ClassName)
		end
	end
	
	return mass
end

character.AntiGravity.Force = Vector3.new(0, weigh(character) * 196.2, 0)
character.AntiGravity.Parent = character.HumanoidRootPart

character.LocalGravity.Target = workspace.Moon
character.LocalGravity:Fire()
character.LocalGravity.Parent = character.HumanoidRootPart

How do I make the character face the right direction, so the feet are always on the moon’s surface?

Thanks.

Use the GravityController module by @EgoMoose, it’s very high quality and it seems to suit your needs,
Wall stick/Gravity Controller

2 Likes