Having lots of trouble with Raycasting (Hitting unexpected parts)

I’ll be quick, I am trying to make a crawl system and I have a raycast to make sure you can’t stand up when you have something above you. My raycast system detects part that are off to the side or not above it. This is a problem.
(Local)Script:

local UserInputService = game:GetService("UserInputService")
local player = script.Parent.Parent
player.CharacterAdded:Wait()
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local crawlAnim = humanoid:LoadAnimation(script.CrawlAnim)
local isCrawling = false



UserInputService.InputBegan:Connect(function(input) 
	if input.KeyCode == Enum.KeyCode.C then
		if not isCrawling then
			humanoid.CameraOffset = Vector3.new(0,-2,0)
			character.Head.CanCollide = false
			character.PrimaryPart.CanCollide = false
			isCrawling = true
			crawlAnim:Play()
			humanoid.JumpPower = 0
			humanoid.WalkSpeed = 9
		else
			local canStand
			local raycastParams = RaycastParams.new()
			raycastParams.RespectCanCollide = true
			raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
			raycastParams.FilterDescendantsInstances = {character, workspace.building}
			canStand = workspace:Raycast(character.PrimaryPart.Position, Vector3.new(character.PrimaryPart.Position.X,character.PrimaryPart.Position.Y+3,character.PrimaryPart.Position.Z),raycastParams)	
			print(canStand)
			if not canStand then
				humanoid.CameraOffset = Vector3.new(0,0,0)
				character.PrimaryPart.CanCollide = false
				character.Head.CanCollide = true
				isCrawling = false
				crawlAnim:Stop()
				humanoid.JumpPower = 50
				humanoid.WalkSpeed = 16
			end
		end	
	end
end)


Video:

dont mind the error in the output, its from a totally different script

The second part of raycast is the direction, not the destination.

Use this instead
Vector3.new(0, 3, 0)

And it works… thanks (3030303030)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.