How to make raycast start at origin?

So my raycast always starts at the origin even though I want to start at the bottom of the part.

Code:

local part = script.Parent

local height = 3
local size = part.Size.Y / 2

local rayOrigin = part.Position - size
local rayDirection = Vector3.new(0, -height, 0) 
local raycast = workspace:Raycast(rayOrigin, rayDirection)

You can’t subtract a scalar value from a vector; you need to specify what is being subtracted and from where - the code below should be the corrected version of what you’re attempting.

local rayOrigin = part.Position - Vector3.new(0, size, 0)

However, I’m unsure if this would work for rotated parts; perhaps try this instead?

local rayOrigin = part.Position - part.CFrame.UpVector * size

I tried both of your solution but they don’t still give me the same results.

The height should be 3 studs above the ground but it returns 1 because it is still starting at the center part position.

Ohh. Sorry, the problem wasn’t actually the raycast.

The problem was that I forgot to add up the height so that it would position it there.

local size = part.Size.Y / 2
local height = HipHeight + size
local newPosition = position + Vector3.new(0, height, 0)

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