I have a gorilla model that will be able to climb trees. To achieve this when the gorilla touches parts tagged as “Trunk” a prismatic constraint will be setup allowing the player to climb up and down. This is determined with a .TouchedEvent
and then using a Shapecast
to ensure the character is actually looking at the tree.
I do this over trusses because the gorilla scales in the game over time and eventually trusses don’t get detected as climbable once you get to a certain size
while task.wait() do
if TouchingTrunk and not Climbing then
if TouchingTrunk:HasTag("Trunk") then
local Params = RaycastParams.new()
Params.FilterDescendantsInstances = {script.Parent, game.Workspace.Terrain}
Params.FilterType = Enum.RaycastFilterType.Exclude
Params.IgnoreWater = true
local Shapecast = game.Workspace:Spherecast(RaycastAttachment.WorldPosition, 4, RaycastAttachment.WorldCFrame.LookVector * 7, Params)
if Shapecast then
warn("Shapecasted") -- Shapecast detected an object
print(Shapecast.Instance)
if Climbing == false and Shapecast.Instance == TouchingTrunk then
Climbing = true
task.spawn(BeginClimbing, TouchingTrunk)
end
else
print("Shapecast Failed") -- Shapecast failed at detecting an object
end
end
task.wait(0.1)
end
end
When the character attempts to jump it will destroy the prismatic constraint and push the character back. The issue is if the character is still touching the tree when it slides down, the shapecast detecting a touch doesn’t register.
So when I first go up to the tree it prints "Shapecasted"
, but when I jump and move forward to “hug the tree” it repeatedly prints "Shapecast Failed"
implying the shapecast doesn’t seem to pick up the tree trunk, until you walk away and go towards it again.
I’m pretty stumped with this one so I figured I would make a devforum post, feel free to ask for any more information