-
What do you want to achieve? Keep it simple and clear!
-I want to make it so that the players can stick to walls and parts adn their gravity changes based on the normal of the part, I also want to make this on my own without needing any module from other people -
What is the issue? Include screenshots / videos if possible!
I can’t seemed to figure out how to offset the player orientation when stick to a part
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried looking into the forums but have found no solutions
The script inside StarterCharacterScripts:
local HumanoidRootPart = script.Parent:WaitForChild("HumanoidRootPart")
local Humanoid = script.Parent:WaitForChild("Humanoid")
local Rootattach = HumanoidRootPart:WaitForChild("RootAttachment")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
workspace.Gravity = 0
local normalG = 9.8
local gravity = Vector3.new(0,0,0)
local facingdirection = Vector3.new(0,0,0)
Humanoid.AutoRotate = false
Humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, false)
Humanoid:SetStateEnabled(Enum.HumanoidStateType.Landed, false)
Humanoid:SetStateEnabled(Enum.HumanoidStateType.Freefall, false)
Humanoid:SetStateEnabled(Enum.HumanoidStateType.Running, false)
Humanoid:SetStateEnabled(Enum.HumanoidStateType.Climbing, false)
Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
script.AlignOrientation.Attachment0 = Rootattach
script.LinearVelocity.Attachment0 = Rootattach
function Raycast()
local ray = Ray.new(HumanoidRootPart.Position, -HumanoidRootPart.CFrame.UpVector)
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Include
params.FilterDescendantsInstances = {workspace.GravityController}
workspace:WaitForChild("Origin").Position = ray.Origin
workspace:WaitForChild("Direction").Position = ray.Origin + ray.Direction * 8
local cast = workspace:Raycast(ray.Origin, ray.Direction * 8, params)
return cast
end
RunService.RenderStepped:Connect(function()
facingdirection = Humanoid.MoveDirection
local raytest = Raycast()
print(raytest)
if raytest then
gravity = -Raycast().Normal * normalG
script.AlignOrientation.CFrame = CFrame.new(HumanoidRootPart.Position, HumanoidRootPart.Position + raytest.Normal) * CFrame.Angles(math.rad(-90),0,0)
if facingdirection == Vector3.new(0,0,0) then
else
script.AlignOrientation.CFrame = CFrame.new(HumanoidRootPart.Position, HumanoidRootPart.Position + (HumanoidRootPart.CFrame.LookVector * Humanoid.MoveDirection.X))
end
else
gravity = Vector3.new(0, -1, 0) * normalG
if Humanoid.MoveDirection.Magnitude > 0 then
script.AlignOrientation.CFrame = CFrame.new(HumanoidRootPart.Position, HumanoidRootPart.Position + Humanoid.MoveDirection)
end
end
gravity += Humanoid.MoveDirection * 16
script.LinearVelocity.VectorVelocity = gravity
--print(Humanoid:GetState())
end)
I just need the solution to this problem, thank you!