Im trying to spawn a spike infront of the player by getting the position infront of the player then raycasting to the floor where the spike would spawn, but its just slightly off for some reason
I created a visualized version of the raycast to more clearly see whats happening
Green Beam - the raycast Direction
Yellow Beam - The position of where the raycast is hitting
heres the script that’s spawning the spike
local function spawnSpikes(player, character, hrpPos, distance)
print("attempting to spawn spike")
local positionInfrontPlayer = character.HumanoidRootPart.Position + (character.HumanoidRootPart.CFrame.LookVector * Vector3.new(distance, 0 ,distance))
print(positionInfrontPlayer)
local rayOrigin = positionInfrontPlayer
local rayDirection = positionInfrontPlayer - Vector3.new(0,50,0)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {character}
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
raycastParams.IgnoreWater = true
local rayResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
if rayResult then
print("found available ground, spawning spike")
local spike = game:GetService("ServerStorage").blackSpike:Clone()
spike.Parent = game.Workspace.particlesholder
spike.Position = rayResult.Position
end
end
any help would be GREATLY appreciated