Thank you for this it’s an interesting read, however my situation is quite complex in my mind and I’m afraid I’m not exactly sure how to implement the solution into it.
This here is the desired result:
Here is the code for the rotation seen in the video:
local MousePoint = UIS:GetMouseLocation()
local TargetWorldToScreen = Camera:WorldToScreenPoint(ActionData.TargetOrigin.Position)
local TargetPoint = Vector2.new(TargetWorldToScreen.X, TargetWorldToScreen.Y)
local Property = ActionData.Property
local a = ActionData.MouseOrigin - TargetPoint
local b = MousePoint - TargetPoint
local Angle = math.acos(a.unit:Dot(b.unit))
local Res = Camera.ViewportSize
local Intersecting = IsIntersecting(
MousePoint, Vector2.new(Res.X,MousePoint.Y),
ActionData.MouseOrigin + a * Res.X, ActionData.MouseOrigin - a * Res.X
)
local OverTheEdge = IsIntersecting(
Vector2.new(Res.X, 0), Vector2.new(Res.X, Res.Y),
ActionData.MouseOrigin + a * Res.X, ActionData.MouseOrigin - a * Res.X
)
local EdgeIntersect
if OverTheEdge then
local IntersectionPoint = FindLineIntersection2D(Vector2.new(Res.X, 0), Vector2.new(Res.X, Res.Y), ActionData.MouseOrigin + a * Res.X, ActionData.MouseOrigin - a * Res.X, true, true)
local YMul = 1
if TargetPoint.Y > ActionData.MouseOrigin.Y then
YMul = -1
end
EdgeIntersect = IsIntersecting(
MousePoint, Vector2.new(Res.X,MousePoint.Y),
IntersectionPoint, Vector2.new(Res.X, Res.Y*YMul)
)
end
if TargetPoint.Y > ActionData.MouseOrigin.Y then
Angle *= -1
end
if not Intersecting and not EdgeIntersect then
Angle *= -1
end
local TargetPointToWorld = Camera:ScreenPointToRay(TargetPoint.X,TargetPoint.Y,5)
ActionData.Target[Property] = CFrame.fromAxisAngle(CFrame.new(TargetPointToWorld.Origin, ActionData.TargetOrigin.Position).LookVector,Angle).Rotation * ActionData.TargetOrigin
ActionData.Target[Property] = CFrame.new(ActionData.TargetOrigin.Position) * ActionData.Target[Property].Rotation
Now using this code with Motor6D transforms it looks like this:
This is of course expected but I have very little idea as to how I should convert that code to function with transform values. I really appreciate it if you can help.