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

Part does not rotate correctly despite being a single line? (FIXED)

Asked by 3 years ago
Edited 3 years ago

At the moment I'm trying to draw a line from one point to another with raycasting by creating a part with the end result.

The raycasting has gone well. What I'm asking for is I want to be able to draw lines in different axes instead of using only the Z unit for ray length to adjust for use cases when the mesh on a line only goes upon an X or Y axis, but not the Z axis (e.g. CylinderMesh only goes along Y axis, but Cylinder shape only goes along X axis).

I've tried using CFrame.Angles(0, math.rad(90), 0) for X axis and an equivalent to Y axis before and after the part's size is set, and I've tried setting Part.Rotation, but the part still rotates really weirdly instead of rotating around the center of the part despite only being a single part (like how you usually manipulate Rotation from the properties menu or use the rotate tool)

if lineAxis == Enum.Axis.Z then

    result.Size = Vector3.new(lineWidth, lineHeight, distance)
    result.CFrame = CFrame.new(Point1, Point2) * CFrame.new(0, 0, -distance / 2) -- this section of the code is fine

elseif lineAxis == Enum.Axis.X then

    result.Size = Vector3.new(distance, lineHeight, lineWidth)
    result.CFrame = CFrame.new(Point1, Point2) * CFrame.new(-distance / 2, 0, 0)
    -- Unsuccessful alternatives:
    -- cframe * CFrame.Angles()
    -- result.Rotation

elseif lineAxis == Enum.Axis.Y then

    result.Size = Vector3.new(lineWidth, distance, lineHeight)
    result.CFrame = CFrame.new(Point1, Point2) * CFrame.new(0, -distance / 2, 0)                
end

The part size swapping for different axes goes fine but it's the rotation that does not perform as intended.

Edit: Just checked the code and I actually might be doing something wrong with the initial CFraming (with Point1 and Point2), I'll check it out and see If I can fix something.

1 answer

Log in to vote
0
Answered by 3 years ago

Nevermind, I checked what I did wrong with the initial CFraming and fixed the issue. I had to rotate the Point1 to Point2 CFrame (with LookAt) before multiplying the CFrame by half of the negative distance.

Ad

Answer this question