Hi! Quick question, how can I match a part’s orientation to a ray’s normal?
I tried checking the DevForum and Wiki, and if I understood correctly, a Raycast Normal vector is basically the perpendicular vector of the ray.
What I’m trying to do is basically spawn parts whose orientation match the terrain’s slope. Example:
I managed to make the parts spawns on the appropriate Y level, but unfortunately I can’t seem to match their orientation to the slope, as you can see in this screenshot:
This is the script:
local function placeSpeedArea(pos,player)
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Blacklist
params.IgnoreWater = false
params.FilterDescendantsInstances = {player.Character,workspace.speed, workspace:WaitForChild("IceShards")}
local origin = Vector3.new(pos.X, pos.Y, pos.Z)
local direction = Vector3.new(0, -1, 0)*100
local ray = Ray.new(origin, direction)
local result = workspace:Raycast(origin,direction,params)
if result and not speedDB then
speedDB = true
local SpeedPad = IcePadModel:Clone()
SpeedPad.Position = Vector3.new(pos.X, result.Position.Y, pos.Z)
--SpeedPad.CFrame = CFrame.new(result.Position, result.Normal)
SpeedPad.Parent = workspace.speed
end
end
I tried using the method mentioned here
SpeedPad.CFrame = CFrame.new(result.Position, result.Position + result.Normal)
But unfortunately all it does is this:
I’m not very good at math nor Raycasting so if someone can explain what I’m doing wrong that would be great. I also tried multiplying the CFrame by 90 and 180, but no difference.