I currently have a dragging system working and moving the objects in front of my camera, but I can’t seem to figure out the rotation aspect. I want the object to retain it’s original rotation when picked up, but still rotate with the camera - somewhat like a viewmodel with its rotation offsetted.
Here is a clip of my current pick up system using AlignPosition:
Here is what I want the system to resemble (G-Mod):
just for info, I’m planning to use AlignOrientation
local UserInputService = game:GetService("UserInputService")
local Camera = workspace.CurrentCamera
local function MouseRay()
local MousePos = UserInputService:GetMouseLocation()
local Point = Camera:ViewportPointToRay(MousePos.X, MousePos.Y)
local Params = RaycastParams.new() --Modify them as you like
Params.FilterType = Enum.RaycastFilterType.Exclude
Params.FilterDescendantsInstances = {}
local RayCast = workspace:Raycast(Point.Origin, Point.Direction)
return RayCast
end
Camera:GetPropertyChangedSignal("Focus"):Connect(function()
local RayResult = MouseRay()
if RayResult then
--Make a tween or align the position of the instance to the rayResult position
end
end)
From what I understand this returns a position and normal value. But how can I use this to rotate the object with the camera as shown in the gmod example video? I already have a pick up system that moves the object in front of the camera, but it doesn’t rotate it, as seen in the first example video.
I don’t know the exact math you’d need to do for this but I believe you should be able to take the picked up objects angle then the destination for wherever the picked up object goes. You then need the angle of the destination facing the camera. You can get that with cframe.lookat or cframe(v3,v3) to return it pointing at something. Then just multiply the angle facing you with the objects angle.
This could just be wrong since I abhor dealing with angles and geometry so I don’t know the functions you’d use for this but this should work since youre just making the object face you then multiply back its original angle.