Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to set the upwards orientation of a part based on a surface normal of ground below?

Asked by 5 years ago

So what I'm trying to do is set the orientation of a part relative to the ground or part beneath. Currently I'm using a ray downwards from the part and FindPartOnRay to get the normal of the surface below. I have no problem positioning the object near the ground but when I try to orient it I'm failing miserably. The code below works only for 1 direction so I'm thinking that the + 90 degrees there is right only in the context of my current direction.

local function setSledOrientationToSurfaceNormal(surfaceNormal)
    surfaceNormal.X = math.abs(surfaceNormal.X)
    surfaceNormal.Y = math.abs(surfaceNormal.Y)
    surfaceNormal.Z = math.abs(surfaceNormal.Z)
    local cframe = sled.CFrame


    sled.CFrame = CFrame.new(cframe.Position, cframe.Position + surfaceNormal)

    sled.Orientation = Vector3.new(sled.Orientation.X  + 90, sled.Orientation.Y, sled.Orientation.Z)
    --sled.Orientation = Vector3.new(sled.Orientation.X, sled.Orientation.Y, sled.Orientation.Z)

end

1 answer

Log in to vote
0
Answered by 5 years ago

If it is unanchor you need to do CFrame's so like Example

sled.Weld.C0 = CFrame.fromEulerAnglesXYZ(math.rad(0),math.rad(0),math.rad(0))

(This is Example)

Ad

Answer this question