Hi, I’m coding a “Kinematic Character Controller” on roblox, completely ditching Humanoids. but i’ve ran into an issue that i can’t seem to fix.
The character completely clips through the tilted part (represents the roof)
What i want to achieve is the character just stops when they run into a space that’s too small to fit through. (Similar to a humanoid behavior)
This is the piece of code that handles the collision:
ProjectVectorOnPlane formula:
local function ProjectVectorOnPlane(vectorToProject : Vector3, planeNormal : Vector3): Vector3
local dotProduct = vectorToProject:Dot(planeNormal)
return vectorToProject - planeNormal * dotProduct
end
Projecting along a plane and sliding the character with it (Ground and Roof uses the same code except the CastDirection is inverted)
SavedData.GetGround = function(Position: Vector3): RaycastResult
local CastDirection = Vector3.new(0, -3, 0)
local Cast = workspace:Blockcast(CFrame.new(Position), Vector3.new(2, 0.125, 2), CastDirection, NCPARAMS)
if Cast then
SavedData.TargetVelocity = VEssentials.ProjectVectorOnPlane(SavedData.TargetVelocity, Cast.Normal)
end
SavedData.GroundRay = Cast
return Cast
end
And the character is being controlled with:
Root:PivotTo(CFrame.new(GroundPosition) * CFrame.lookAlong(StateData.TargetVelocity, VEssentials.GetHorizontalProjection(workspace.CurrentCamera.CFrame.LookVector)))
GetHorizontalProjection() is Vector3.new(X.X, 0, X.Z)
The top & bottom debug part represents the roof cast’s hit position (green if hit and yellow if nil)
The red and blue is the collision check for rays to go depending on the player’s Velocity
Any possible help is greatly appreciated,
Cheers!