Incorrect direction for raycasting


I was wondering what could be wrong with this direction and raycast. No errors to the console just not going in the right direction.

	local origin = ShootPart.Position
	local direction = (mousepos.Position - origin).Unit * Tool.Range.Value

        local rayresult = game.Workspace:Raycast(origin, direction,raycastParams)
1 Like

What is mousepos? Is it a 2D vector or 3D vector?

1 Like

Mouse pos is the players mouse.Hit property

local mouse = player:GetMouse()

local mousepos = mouse.Hit

Did you debug the origin and the direction variables to check if they are correct? You would do that with for example inserting parts at the position of the origin and direction.

Hey! This video shows a part being created at the origin with the rotation of the ray

External Media