I’m working on a platformer combat game and I’m having an issue with players jumping into elevated pads. Sometimes, when a player jumps into a pad, my collision script doesn’t detect the platform and will get the player stuck and fling them. I have no problem with the flinging issue, my main problem is the collision detection with the raycast.
Video:
Source Code:this is run on the client, obviously. the collidable parts are stored in a folder in workspace and are cancollide = false by default.
function replicator:FloorCheck(obj)
local r = Ray.new(obj.Position+Vector3.new(0,-2.2,0),Vector3.new(0,-1e2,0))
local p,pos = workspace:FindPartOnRayWithWhitelist(r,{workspace.Collidable})
if p and p.Name:match('Platform') then
p.CanCollide = true
else
for _,v in ipairs(workspace.Collidable:GetChildren()) do
if v.Name:match('Platform') then
v.CanCollide = false
end
end
end
local c = ASSETS.DebugPart:Clone() --debug part of code, shown with the white dot under the player
c.Parent = workspace.LiveEffectsasdf
c.Position = pos
Debris:AddItem(c,0.01)
end
I am not really sure what you mean but I am assuming that you are having problems with the can collide turning back to true when the player is going through the block?
If that is so then
You could cast a ray from the player’s foot and if it detects it then change the collision
game:GetService('RunService').Stepped:Connect(function()
local ray = Ray.new(game.Players.LocalPlayer.Character.HumanoidRootPart.Position, Vector3.new(0, 30, 0))
local ray2 = Ray.new(game.Players.LocalPlayer.Character.RightFoot.Position, Vector3.new(0, -30, 0))
local hit, pos = workspace:FindPartOnRay(ray, game.Players.LocalPlayer.Character)
local hit2, pos2 = workspace:FindPartOnRay(ray2, game.Players.LocalPlayer.Character)
if hit and hit.Name == 'Cloud' then
hit.CanCollide = false
end
if hit2 and hit2.Name == 'Cloud' then
hit2.CanCollide = true
end
end)