Today I was thinking of creating a parkour script similar to how vaulting works in Phantom Forces or Parkour. But while creating the raycasting part of it, I got some weird results.
Here’s a video of the issue:
--important
local rep = game:GetService("ReplicatedStorage")
local Input = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
--instances
local char = plr.Character or plr.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local root = humanoid.RootPart or char:WaitForChild("HumanoidRootPart")
local part1 = workspace:WaitForChild("DebugPart1")
local part2 = workspace:WaitForChild("DebugPart2")
local part3 = workspace:WaitForChild("DebugPart3")
local part4 = workspace:WaitForChild("DebugPart4")
local part5 = workspace:WaitForChild("DebugPart5")
--variables
local params = RaycastParams.new()
--setup
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
part1.Parent = char
part2.Parent = char
part3.Parent = char
part4.Parent = char
part5.Parent = char
params.FilterType = Enum.RaycastFilterType.Blacklist
params.FilterDescendantsInstances = {char}
--connecting
Input.JumpRequest:Connect(function()
if humanoid:GetState() ~= Enum.HumanoidStateType.Freefall then
local EndPos = (root.CFrame * CFrame.new(0, 0, -2)).Position
local lowerVector = script.lowerVector.Value--Vector3.new(0, -1.5, 0)
local lowerStart = root.Position+lowerVector
local lowerRay = workspace:Raycast(lowerStart, EndPos+lowerVector, params)
local upperVector = script.upperVector.Value--Vector3.new(0, 0.5, 0)
local upperStart = root.Position+upperVector
local upperRay = workspace:Raycast(upperStart, EndPos+upperVector, params)
local lowDistance = lowerRay and (lowerRay.Position-lowerStart).Magnitude or 2
local upDistance = upperRay and (upperRay.Position-upperStart).Magnitude or 2
if lowDistance < upDistance then
warn("vault test succeeded")
else
warn("didn't vault")
end
if lowerRay then
part1.Position = lowerRay.Position
else
part1.Position = EndPos+lowerVector
end part3.Position = lowerStart
if upperRay then
part2.Position = upperRay.Position
else
part2.Position = EndPos+upperVector
end part4.Position = upperStart
part5.Position = EndPos
print(lowDistance .. "|" .. upDistance)
end
end)
I really am confused about this string behavior and I don’t know whether I have done something wrong or I should post this in the Engine Bugs section.