The script and models are currently a placeholder but the model which is supposed to be the pick is not turning fully/properly towards the mouse and does strange rotations sometimes. https://i.gyazo.com/3426daf8e5d68bb05658ce38a4afc8c0.mp4
local part = script.Parent.Frame.ViewportFrame.Model.Union
local Mouse = game.Players.LocalPlayer:GetMouse()
if Mouse then -- i know this should be here
game:GetService("RunService").RenderStepped:Connect(function()
local pos = Vector3.new(Mouse.Hit.Position.X, part.Position.Z, part.Position.Z)
part.CFrame = CFrame.new(part.Position, pos)
end)
end
i have tried all x y and z in all mouse and part but none have gotten best/good results
This is because Mouse.Hit.Position is where the mouse lands in 3d space, so basically it’s touching actual parts in your Workspace. This means that, instead of touching the baseplate which is far away, it’s accidentally touching your lockpick model, meaning that Mouse.Hit.Position.Z would be closer to the camera than if it were to hit the Baseplate. That’s why it looks like it’s jumping forward.
As a quick sidenote, LocalPlayer’s Mouse is deprecated, and there are better alternatives out there. Try using UserInputService:GetMouseLocation(), which returns a Vector2 of the Mouse’s location on the camera Viewport. You can also use Camera:ViewportPointToRay() to get the mouse’s location in studs.
Here’s an example:
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local part = script.Parent.Frame.ViewportFrame.Model.Union
RunService:BindToRenderStep("LOCKPICK_RENDERING", Enum.RenderPriority.Input.Value, function()
local camera = workspace.CurrentCamera
if camera then
local mouseLocation = UserInputService:GetMouseLocation()
local cameraRay = camera:ViewportPointToRay(mouseLocation.X, mouseLocation.Y)
local partPosition = part.Position
local mousePosition = Vector3.new(cameraRay.Direction.X, part.Position.Z, part.Position.Z)
part.CFrame = CFrame.lookAt(partPosition, mousePosition)
end
end)
I see. For the mousePosition variable, you could try doing Vector3.new(cameraRay.Direction.X, cameraRay.Direction.Y, part.Position.Z) which takes the camera ray’s Y direction into account, and leaves the part’s Z alone. This should solve everything.