I got bored, so I wanted to make some antigravity. I want my character to be orientated perpendicular to the surfaces its being forced onto:
Simple, but not easy.
See my current script
A Server Script
--scripted by GreekForge
local rs = game:GetService("RunService")
local char = script.Parent
local hrp = char:WaitForChild("HumanoidRootPart")
local hum = char:WaitForChild("Humanoid")
local cMass = 0;
local tSpeed = 0.35
--create force
local grav = Instance.new("BodyForce")
grav.Name = "Gravity"
grav.Force = Vector3.new(0, -1, 0)
grav.Parent = hrp
local orient = Instance.new("BodyGyro")
orient.Name = "Orient"
orient.MaxTorque = Vector3.new(4000000, 400000, 4000000)
orient.D = 100000
orient.P = 10000000
orient.CFrame = CFrame.new(hrp.Position, hrp.CFrame.LookVector)
orient.Parent = hrp
local function getMassOfModel(model)
local mass = 1;
for _, p in pairs(model:GetChildren()) do
if p:IsA("UnionOperation") or p:IsA("MeshPart") or p:IsA("BasePart") then
mass = mass + (p.Size.X*p.Size.Y*p.Size.Z)*2
end
end
return mass;
end
cMass = getMassOfModel(char)
rs.Stepped:Connect(function(delta)
local offset = hrp.Velocity.Unit
local ray = Ray.new(hrp.Position,(-hrp.CFrame.UpVector + offset).Unit * 100)
local h, p, n = workspace:FindPartOnRay(ray, char)
if h then
grav.Force = -n * cMass * 100 --grav
local ang = (math.rad(90) - math.acos(n:Dot(hrp.CFrame.RightVector)))
local pVec = n:Cross(hrp.CFrame.RightVector).Unit
orient.CFrame = CFrame.new(hrp.Position, (hrp.Position + pVec)) * CFrame.new(0, 0, ang*100)
-- hrp.CFrame = CFrame.new(hrp.Position, (hrp.Position + pVec)) * CFrame.new(0, 0, -ang)
else
grav.Force = Vector3.new(0, -1, 0) * cMass * 100
end
end)
Only applies the force correctly, it doesn’t orientate correctly.
And when its running it looks as if the player is jittering, like something is competing against the body gyro:
Kinda hard to show in a picture though.
Any ideas?