Still trying to make a gravity script

Soooooooooooooooooo…

I am still trying to complete that gravity script I started. I managed to get the player attracted to the planetoid with the LocalScript below:

local character = script.Parent.PrimaryPart
local planetoid = game.Workspace.Planetoid
local atmosphere = planetoid.Atmosphere
function gravityFunction()
	if character and not character:FindFirstChild("gravityPoint0") then
		local gravity = Instance.new("LineForce")
		local gravityPoint0 = Instance.new("Attachment")
		local gravityPoint1 = Instance.new("Attachment")
		local bipedalismHelper = Instance.new("Part")
		local bipedalismWeld = Instance.new("WeldConstraint")
		gravity.Parent = planetoid
		gravity.Name = "gravity"
		gravity.ApplyAtCenterOfMass = true
		gravity.Magnitude = 1000
		gravity.Attachment0 = gravityPoint0
		gravity.Attachment1 = gravityPoint1
		gravityPoint0.Parent = character
		gravityPoint0.Name = "gravityPoint0"
		gravityPoint1.Parent = planetoid
		gravityPoint1.Name = "gravityPoint1"
		bipedalismHelper.CanCollide = false
		bipedalismHelper.Transparency = 1
		bipedalismHelper.Parent = character
		bipedalismHelper.Size = Vector3.new(2, 0.5, 1)
		bipedalismHelper.Position = character.Position + Vector3.new(0, -6, 0)
		bipedalismHelper.Orientation = Vector3.new(0, 0, 90)
		bipedalismHelper.Name = "bipedalismHelper"
		bipedalismWeld.Parent = bipedalismHelper
		bipedalismWeld.Part0 = bipedalismHelper
		bipedalismWeld.Part1 = character
	end
	if character and character:FindFirstChild("gravityPoint0") then
		local bh = character.bipedalismHelper
		bh.CFrame = CFrame.lookAt(character.CFrame.YVector, planetoid.Position)
	end
end

atmosphere.Touched:Connect(gravityFunction)

The end result is funny, but is far away from anything I would consider the mechanics of gravity. I tried using AlignOrientation, but apparently, if you use CFrame.lookAt in on an attachment, the game lags like crazy, and I need the attachment to look in the right direction constantly. Any alternative ways of making the bottomSurface of a part look at a workspace part?

2 Likes