- What do you want to achieve?
I’m trying to make a part face the normal of the blockcast and later lerp the rig to face the direction of the normal
- What is the issue?
The only way I can make the part face the normal is if I set the orientation manually. I’ve tried to use Cframe.lookat() but it seems to be giving the slope of the object and not the direction of the surface.
the code
local humanoidrig = script.Parent
local humanoidrootpart = humanoidrig.HumanoidRootPart
local size = Vector3.new(1,1,1)
local directionpart = workspace.Direction
local visualizepart = Instance.new("Part")
visualizepart.Anchored = true
visualizepart.CanCollide = false
visualizepart.Size = size
visualizepart.Name = "VisualPart"
visualizepart.Transparency = .5
visualizepart.Parent = workspace
while true do
task.wait()
local params = RaycastParams.new()
params.FilterDescendantsInstances = {humanoidrig, visualizepart, directionpart}
params.FilterType = Enum.RaycastFilterType.Exclude
local direction = humanoidrootpart.CFrame.UpVector*-5
local blockcast = workspace:Blockcast(humanoidrootpart.CFrame, size, direction, params)
if blockcast then
print(blockcast.Instance)
visualizepart.Rotation = humanoidrootpart.Rotation
visualizepart.CFrame = humanoidrootpart.CFrame + direction.Unit * blockcast.Distance
directionpart.Position = humanoidrootpart.Position + direction.Unit * blockcast.Distance
directionpart.Orientation = humanoidrootpart.Orientation -- manually set the rotation
-- slope angle directionpart.CFrame = CFrame.lookAt(directionpart.Position, directionpart.Position + blockcast.Normal)
else
print("no blockcast")
visualizepart.Orientation = humanoidrootpart.Orientation
visualizepart.Position = humanoidrootpart.Position + direction
directionpart.Position = Vector3.new(0,0,0)
end
end
here is manually setting rotation
https://gyazo.com/90d23af9a409329f9fcaf87db0687f81
here is using the slope angle comment code instead
https://gyazo.com/4f27fc0e9b62df898839f50578048afd