So, I have been messing around trying to get the SurfaceNormal of a ray being casted down from a seat. Im attempting to get a horse to stand oriented with the ground.
This is my code…
local function UpdateSurfaceNormal(seat, gyro)
local ray = Ray.new(seat.Position, Vector3.new(0, -20, 0))
local target, position, surfaceNormal = workspace:FindPartOnRayWithWhitelist(ray, {workspace.Terrain})
local slopeAngle = math.atan2(surfaceNormal.Z, surfaceNormal.Y)
gyro.CFrame = seat.CFrame:ToObjectSpace(CFrame.Angles(slopeAngle, 0, 0))
end
This is my result…
Any suggestions or advice on how I can get this to be more accurate? To clarify, I’m casting a ray from the center of the seat (middle of the horse), down to the ground. Im also using a BodyVelocity to move the horse forward/backward.