So I have a object I want to spawn on top of the ground, so want it to do is make it spawn 10 studs from the player and on top of the ground. However, the raycast seems to be ignoring the ground, and instead goes through it and hits the ocean, and spawning the part on top of the part named ocean, instead of the ground.
This is the code:
local offset = Vector3.new(0,0,-10)
local part = Instance.new("Part", workspace)
campfire.base.CFrame = plr.Character.HumanoidRootPart.CFrame*CFrame.new(offset)
local rayOrigin = Vector3.new(campfire.base.Position)
part.Position = campfire.base.Position
part.Anchored = true
part.Size = Vector3.new(1,1,1)
local rayDirection = Vector3.new(0, -1, 0)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {campfire}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
if raycastResult then
print(raycastResult.Position)
campfire.base.CFrame = CFrame.new(campfire.base.Position.X,raycastResult.Position.Y + .51,campfire.base.Position.Z)
end
Now this gray part you see in this image is a part instance I created which is the position of the raycast position. The raycast position is placed correctly, also, I know the object I want to spawn has the correct hotbox because earlier while I was testing it was spawning on top of the ground just right, now in my testing I just wanted to make sure I had the raycast position correct, because earlier the raycast position was based on the world position of the part instead of its directional axis position, meaning sometimes when there’s a ledge, based on where the characters direction is, it either floats above the ledge or it spawns on the ground below. So, what’s wrong?