I’m making a ledge grab mechanic in Roblox using raycasting, all is working well except the wall strafing
Here’s a video that kind of explains all the problems
robloxapp-20220326-0231044.wmv (3.4 MB)
Also Red/Yellow dots “Should show the origin” and Blue/Teal dot “Should show the direction”, and green is a success indicator for if it hits a block so the player can move left/right.
The problem is that the rays don’t seem to be going in the right direction for some reason. In the video
you can see that on one side the strafing works but on the other side it doesn’t, and on the high wall the green dot is way off to the left of the player’s origin and direction dots.
Here my raycasting code
function StrafL()
local Origin = RootPart.Position + RootPart.CFrame.RightVector * -4.5
local Direction = RootPart.Position + (RootPart.CFrame.LookVector * 1.5) + RootPart.CFrame.RightVector * -4.5
VisualBlock(Origin,Color3.new(1, 0, 0),0.1)
VisualBlock(Direction,Color3.new(0, 1, 0.635294),0.1)
local Parms = RaycastParams.new()
Parms.FilterDescendantsInstances = Character:GetDescendants()
Parms.FilterType = Enum.RaycastFilterType.Blacklist
local LedgeCheck = workspace:Raycast(Origin, Direction, Parms)
if LedgeCheck then
VisualBlock(LedgeCheck.Position,Color3.new(0.0666667, 1, 0),0.3)
end
if LedgeCheck and Holding == true then
local Velo = Instance.new("BodyVelocity",RootPart)
RootPart.Anchored = false
Velo.MaxForce = Vector3.new(1,1,1) * math.huge
Velo.Velocity = RootPart.CFrame.RightVector * -5
HoldA:Stop() StrafLeftA:Play()
game.Debris:AddItem(Velo,.75)
Holding = false
wait(.75)
RootPart.Anchored = true
HoldA:Play()
Holding = true
end
end
function StrafR()
local Origin = RootPart.Position + RootPart.CFrame.RightVector * 4.5
local Direction = RootPart.Position + (RootPart.CFrame.LookVector * 1.5) + RootPart.CFrame.RightVector * 4.5
VisualBlock(Origin,Color3.new(1, 0.85098, 0),0.1)
VisualBlock(Direction,Color3.new(0, 0.180392, 1),0.1)
local Parms = RaycastParams.new()
Parms.FilterDescendantsInstances = Character:GetDescendants()
Parms.FilterType = Enum.RaycastFilterType.Blacklist
local LedgeCheck = workspace:Raycast(Origin, Direction, Parms)
if LedgeCheck then
VisualBlock(LedgeCheck.Position,Color3.new(0.0666667, 1, 0),0.3)
end
if LedgeCheck and Holding == true then
local Velo = Instance.new("BodyVelocity",RootPart)
RootPart.Anchored = false
Velo.MaxForce = Vector3.new(1,1,1) * math.huge
Velo.Velocity = RootPart.CFrame.RightVector * 5
HoldA:Stop() StrafRightA:Play()
game.Debris:AddItem(Velo,.75)
Holding = false
wait(.75)
RootPart.Anchored = true
HoldA:Play()
Holding = true
end
end
StrafR, Makes the player try to strafe right: this function is fired when the player presses “E”
StrafL, Makes the player try to strafe Left: this function is fired when the player presses “Q”
I can’t really find a way to fix this, help would be very appreciated!