Making a system that requires detecting blocks above the players head upon jumping. It works fine, however a large problem arises if the block is too far close to the player’s head.
In the case where the block is too close, the character jumps and stops instantly as if colliding, despite there being a large distance between the head and the block. For example:
The red line represents the max height that the player can jump up to (essentially nothing) before stopping as if a collision happened. The yellow just shows that there is in fact a large distance.
I’ve tried completely disabling head collisions, even moving the head away entirely, yet the effect still remains.
Is there anything I can do to fix it? Is there a way I can fork the default roblox humanoid scripts?
Hey! This isn’t really your script, it’s how humanoid collisions work. Roblox physics can detect collisions SLIGHTLY before parts visually touch, especially with multiple body parts involved.
What you can try ;
Disable collisions on most character parts and only keep HumanoidRootPart collidable
for _, part in ipairs(character:GetDescendants()) do
if part:IsA("BasePart") and part.Name ~= "HumanoidRootPart" then
part.CanCollide = false
end
end
Don’t rely on physical collisions for checks like “is something above the head”
Use a raycast instead:
local result = workspace:Raycast(character.Head.Position, Vector3.new(0, 5, 0))
If you still want collisions, use collision groups instead of default collisions
Hi! I am using raycasts for the detection on the client, I fire the raycast so that it lands .3 studs above the head (answer to @DataSigh question aswell), and it works just fine, but the collision gap I explained exceeds this unfortunately. Keeping only the HumanoidRootPart collidable unfortunately doesn’t solve the issue either, and there is still this invisible collision between the head and the block above. Because of this I don’t think that the default physics are a problem, maybe something with the way humanoids are handled? And if so is there something I can do to help it?
Found my own solution through making the blocks sort of one-way collideable, only turning on canCollide when the top of the head is over the bottom of the block. Did find that the humanoid FloorMaterial never switches to Air during this happening despite the player very clearly leaving the ground, so I made my own custom raycast to get the actual FloorMaterial.