You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? I want to make the movement part of wall climbing for my game.
-
What is the issue? I can’t figure out the math to make the movedir variable relative to the normal of my ray.
-
What solutions have you tried so far? I have tried to use some sources, like DevForum, ChatGPT, Google, and YouTube.
If it helps, I have my script here.
local char = script.Parent
local climbing = false
local playercanclimb = false
local playerstable = {workspace:WaitForChild("Ocean"), workspace:WaitForChild("Swim")}
local normal
local raypos = nil
local bodypos = nil
local wall = nil
game:GetService("RunService").Heartbeat:Connect(function()
for i, v in pairs(workspace:GetChildren()) do
if v:FindFirstChild("Humanoid") and not table.find(playerstable, v) then
table.insert(playerstable, v)
end
end
local params = RaycastParams.new()
params.FilterDescendantsInstances = playerstable
params.FilterType = Enum.RaycastFilterType.Exclude
local ray = workspace:Raycast(char.HumanoidRootPart.Position, char.HumanoidRootPart.CFrame.LookVector * 2, params)
if ray then
playercanclimb = true
normal = ray.Normal
raypos = ray.Position
wall = ray.Instance
else
if climbing == true then
print("No Longer Climbing")
end
playercanclimb = false
climbing = false
raypos = nil
wall = nil
end
end)
game:GetService("UserInputService").InputBegan:Connect(function(inp, proc)
if proc or inp.KeyCode ~= Enum.KeyCode.Space then return end
if playercanclimb and not climbing then
climbing = true
print("Climbing")
return
elseif climbing then
climbing = false
print("No Longer Climbing")
end
end)
workspace.ChildRemoved:Connect(function(child)
if child:FindFirstChild("Humanoid") then
for i, v in pairs(playerstable) do
if v == child then
table.remove(playerstable, i)
end
end
end
end)
local movedir = Vector3.new(0, 0, 0)
while task.wait() do
while climbing do
char.Humanoid.PlatformStand = true
local forward = -normal:Cross(Vector3.new(0, 1, 0)).Unit
local up = forward:Cross(-normal).Unit
if char.Humanoid.MoveDirection.Magnitude ~= 0 then
movedir = char.Humanoid.MoveDirection
movedir = Vector3.new(movedir.X, movedir.Z, 0)
char.HumanoidRootPart.AssemblyLinearVelocity = (movedir * 100)
else
char.HumanoidRootPart.AssemblyLinearVelocity = Vector3.new(0, 0, 0)
end
if not bodypos then
print("Creating BodyPos")
bodypos = Instance.new("BodyPosition")
bodypos.D = 600
bodypos.P = 10000
bodypos.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
bodypos.Parent = char:WaitForChild("HumanoidRootPart")
print(bodypos.Parent.Name)
end
bodypos.Position = CFrame.fromMatrix(char.HumanoidRootPart.Position, forward, up).Position + (char.HumanoidRootPart.CFrame.LookVector * 0.1)
char.HumanoidRootPart.CFrame = CFrame.fromMatrix(char.HumanoidRootPart.Position, forward, up)
char.Humanoid.AutoRotate = false
task.wait()
end
while not climbing do
if bodypos ~= nil then
print("Sigma")
game:GetService("Debris"):AddItem(bodypos, 0)
char.Humanoid.PlatformStand = false
bodypos = nil
char.HumanoidRootPart.AssemblyLinearVelocity = Vector3.new(0, 0, 0)
movedir = Vector3.new(0, 0, 0)
if game:GetService("UserInputService").MouseBehavior == Enum.MouseBehavior.LockCenter then
char.Humanoid.AutoRotate = true
print("Re-Enabling Shiftlock!")
end
end
task.wait()
end
end
If you can find a solution on any of the things that I searched on, I’m sorry. I’m very bad at finding answers to more obscure questions on the internet, and this is my first post.