I am working on a climbing system for my game that uses ray casts to detect where the player is and how far they are from a climbable wall. I get an error (Unable to cast Instance to Vector3) however it is not concerning my variables, instead it’s erroring this:
local raycastResult = workspace:Raycast(rayOrigin, rayDirection)
I have searched for a solution however I cannot find one that casts from a humanoid/player, only the player’s head. I have tried adding .Position to my Humanoid declaration line here:
local rayOrigin = script.Parent:WaitForChild("Humanoid", 100)
However it errors once again. My entire code for just the ray cast is here, as I want to finish this part before I get to moving the player:
local rayOrigin = script.Parent:WaitForChild("Humanoid", 100)
local rayDirection = Vector3.new(0, 0, 10)
local raycastResult = workspace:Raycast(rayOrigin, rayDirection)
local function rayHit()
if raycastResult then
local hitPart = raycastResult.Instance
if hitPart.isClimbable == true then
print("Raycast hit!")
end
end
end
My script is located in StarterCharacterScripts incase anyone asks. I am thinking it might be something to do with the hitPart.Instance line, however that makes no sense since I didn’t tie a Vector3 to it.
local Root = script.Parent:WaitForChild("HumanoidRootPart", 100)
local rayOrigin = Root.Position
local rayDirection = Vector3.new(0, 0, 10)
local raycastResult = workspace:Raycast(rayOrigin, rayDirection)
local function rayHit()
if raycastResult then
local hitPart = raycastResult.Instance
if hitPart.isClimbable == true then
print("Raycast hit!")
end
end
end
If so, I get no errors, however, the ray cast is not hitting the part/it’s not detecting it.
the ray direction should be changed and you forgot to call the rayhit function
local Root = script.Parent:WaitForChild("HumanoidRootPart", 100)
local rayOrigin = Root.Position
local rayDirection = Root.CFrame.LookVector * 1000
local raycastResult = workspace:Raycast(rayOrigin, rayDirection)
local function rayHit()
if raycastResult then
local hitPart = raycastResult.Instance
if hitPart.isClimbable == true then
print("Raycast hit!")
end
end
end
rayHit()