Hello guys. I’m trying to recreate handles from roblox studio (but with my own design):
This handles work PERFECTLY if camera’s rotation is perfect too (ex: for Y axis perfect will be TOP and BOTTOM views from view selector.
But if camera changes its’ orientation, my calculation become very very wrong, and Position translated along normal CFrame is converted to strange POSITION numbers:
(-35, 22, -284) when camera rotated by 1 angle,
(-83, -22, -271) from the same position but with another angle,
(-86, 112, -246) from SAME position but from perfect top angle
(perfect top angle (true position))
I tried to look into my code, and don’t find anything suspicious, which can cause this problems:
--The only thing that I change RN is ManualCFrame's orientation, position is 0,0,0
local Axis = string.sub(Object.Name, 1, 1) --"Y", "X" or "Z"
local success = true
local Hypothenuse = 0
local MouseDirection = Mouse.UnitRay.Direction
local ManualCFrame = CFrame.new(PlaneManualParams[1]) * CFrame.Angles(math.rad(PlaneManualParams[2].X), math.rad(PlaneManualParams[2].Y), math.rad(PlaneManualParams[2].Z))
local PlaneCameraRelative = nil
if Axis == "Y" then
--plane XZ
local PlaneRotated = ManualCFrame * CFrame.Angles(0, 0, 0)
local PlaneDirection = (PlaneRotated).LookVector
PlaneCameraRelative = PlaneRotated:Inverse() * workspace.CurrentCamera.CFrame
local PlaneCameraLenght = -PlaneCameraRelative.Position.Y
local MouseOnPlaneDirection = CFrame.fromOrientation(PlaneRotated:ToOrientation()):Inverse() * CFrame.new(MouseDirection.X, MouseDirection.Y, MouseDirection.Z)
Hypothenuse = PlaneCameraLenght / MouseOnPlaneDirection.Position.Y
warn(PlaneRotated)
end
--other axises X and Z
local MouseHit = MouseDirection * Hypothenuse
--warn(MouseHit)
local MouseAlongAxis = Vector2.new(MouseHit.Z, MouseHit.X)
PlaneCameraRelative = PlaneCameraRelative:Inverse()
local CameraAlongAxis = Vector2.new(-PlaneCameraRelative.Position.Y, PlaneCameraRelative.Position.X)
local MouseWithCamera = MouseAlongAxis + CameraAlongAxis
warn(PlaneCameraRelative) --Somewhy diffirent rotation causes diffirent position too.
warn(MouseDirection)
warn(MouseAlongAxis.Y, MouseAlongAxis.X)
warn(CameraAlongAxis.Y, CameraAlongAxis.X)
warn(MouseWithCamera.Y, MouseWithCamera.X)
RotateHandlesDrag(Axis, MouseWithCamera)
Also I tried print Camera’s CFrame using command bar:
There’s position changes too, but it’s not that big - around 2 studs only
Can someone tell me, what’s wrong with my calculations, and why my camera gives SO diffirent results when trying to rotate it?