I’m anchoring the humanoid root part and setting its CFrame. How would I detect collisions and stop it from moving into parts?
You could check if humanoid root part (or any other part of character) touches a part that isn’t meant to be climbable (in this case, the baseplate).
If the player touches a part (with their head or torso) that you are meant to collide with, it will stop the script that runs the wall climb function.
For example, you could set attribute to parts that you are meant to climb on and then check with a script if the part that just collided with a player has the Climbable attribute as true. If it has the attribute, it will continue the climbing script, if it doesn’t the player will stop climbing.
That’s just my general idea of what I would try to do.
A suggestion to handle this approach is by raycasting between the humanoid root part and the ground. If the following condition checks that the vertical component is negative, then the humanoid root part cframe will go up based on how much the character sinks into the ground by raycast.
local baseplate = --baseplate in workspace
local players = game:GetService("Players")
local player = players.PlayerAdded:Wait()
local character = player.CharacterAdded:Wait()
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantInstances = {character}
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
local hrp = character:FindFirstChild("HumanoidRootPart")
local raycast = workspace:Raycast(hrp, Vector3.new(0,-5,0),raycastParams)
local raycastCF = raycast.Instance.CFrame
if raycastCF.Y < 4 and raycast ~= nil then
hrp.CFrame = hrp.CFrame:ToObjectSpace(raycastCF)
end
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.