Why does this not work? I’m not good with raycasts. I looked up how to do it properly but i’m missing something.
local Part = Instance.new("Part", workspace) Part.Size = vector3.new(1,1,1)
local OriginalPosition = Character.HumanoidRootPart.Position
local EndPosition = OriginalPosition - Vector3.new(0,-10,0)
local RaycastParams = RaycastParams.new()
RaycastParams.FilterDescendantsInstances = {Character}
RaycastParams.FilterType = Enum.RaycastFilterType.Exclude
local Direction = OriginalPos - EndPosition
local RayRay = Work:Raycast(OriginalPos, Direction, RaycastParams)
Part.Position = OriginalPosition
if RayRay then
Part.Position = RayRay
end
So basically it just raycasts from the player’s position, to 10 studs below the player. The Part should appear in the Baseplate below the player, but instead it aways appears in the HumanoidRootPart position because the Raycast doesn’t work
Direction is defined as End - Origin, currently you are taking the EndPosition, (which is OriginalPosition - Vector3.new(0,-10,0)) and subtracting that from your origin again.
Just flip flop your direction equation and you should be good.
Although in this case, you could just use Vector3.new(0, -10, 0) as your direction. But this is an important fact to keep in mind.
local Direction = EndPosition - OriginalPos
--or
local Direction = Vector3.new(0, -10, 0)
P.S. I would recommend you always take the unit of your direction and multiply it to be however long you want it.
local RayLength = 10
local Direction = (EndPosition - OriginalPos).Unit * RayLength
For the general case; if you want to shoot a ray in some specific direction for some specific distance, then you’d want this as End - Origin would only give you a vector pointing just far enough to reach the end (Assuming you want the ray to go a different distance than the end point).
In this specific case, it doesn’t really do anything since its pointing straight downwards–but I thought I would include it anyways since it can be helpful if you want to make a projectile of some kind.