Hello guys! I’m making my plugin which should help people work with terrain faster.
But I stuck with some problems, one of them is Cone/CylinderHandleAdornments, which I want to use for dragger and rotate tools.
You will ask why I don’t want use built-in Handles and ArcHandles? I don’t want use them because I don’t love their style at all.
So I made my own “Handles” for rotation and move:
But I got one big problem when I tried to script their functionality. HandleAdornments have less. For example, they haven’t MouseDrag, which gives:
face: NormalId; distance: number
For Handles, and
axis: Axis; relativeAngle: number; deltaRadius: number
For ArcHandles
So, when I tried to make this function myself, I got stuck with another problem: IDK how to properly calculate everything:
First thing that IDK how to calculate distance for move tool. On FIRST picture everything seems very easy:
- Cast ray on that plane.
- Then got distance from center to that dot.
- Tada you got result.
I did that. And found problem: What if camera don’t see this plane? For example, if camera looks up. I tried: and got inversion. So if mouse looking right, script means that I’m moving left. (like roblox does xd). But this way CANNOT be implemented for Y-axis
Another way I can say is try to find intersection with mouse ray and (for this example) X-axis.
While this idea I liked more, I got another problem: What if this 2 vectors just won’t cross at all?
(yellow dot is cursor (IK that it’s bad)
I believe that this way is better than previous, but I need a bit of help with it: how I can adjust calculations to hit X-axis?
This’s part of code for detecting intersection with plane:
local MouseDirection = Mouse.UnitRay.Direction
local PlaneCFrame = CFrame.new() --Center of plane should be here.
local PlaneDirection = (PlaneCFrame * CFrame.Angles(math.pi / 2, 0, 0)).LookVector --Top direction of plane.
local PlaneCameraRelative = PlaneCFrame:Inverse() * workspace.CurrentCamera.CFrame
local PlaneCameraLenght = -PlaneCameraRelative.Position.Y --How high camera is from plane.
local MouseOnPlaneDirection = CFrame.fromOrientation(PlaneCFrame:ToOrientation()):Inverse() * CFrame.new(MouseDirection.X, MouseDirection.Y, MouseDirection.Z)
local MouseHypothenuseLenght = PlaneCameraLenght / MouseOnPlaneDirection.Position.Y
--MouseHypothenuseLenght is How much we need multiply MouseDirection to hit plane
Can someone here help me make this code work for only 1 axis, but not plane?
(Here you can see white “Planet” - center of plane, and white grid with blue part - where mouse hits plane.