Hi there! I’m having a strange problem where PlayerMouse.Hit is significantly off from the actual position of the cursor’s position in the 3D world while the CurrentCamera is set to Scriptable.
In the video above, the small, white brick shows the PlayerMouse.Hit position which is visibly off by a significant factor in comparison to the actual mouse. Also testing the Target property, I found out that the result value agrees with the Hit.
There are times (maybe like a 10% chance) where the player mouse actually does work as intended. What makes me confident that this is definitely a Roblox issue to some extent is that the mouse behaves as expected when the camera settings are not set to Scriptable (refer to video below).
Here are some code snippets, but I’m not sure if they give much detail.
mouse.Button1Down:connect(function()
mouseDown = true
while mouseDown do
game:GetService("RunService").RenderStepped:wait()
local target = mouse.Hit.p + Vector3.new(0, currentPos.y - mouse.Hit.p.y, 0)
currentPos = (CFrame.new(currentPos, target) * CFrame.new(0, 0, -0.25)).p
end
end)
spawn(function()
while true do
cursorPart.CFrame = mouse.Hit
local target = mouse.Hit.p + Vector3.new(0, currentPos.y - mouse.Hit.p.y, 0)
local newCFrame = CFrame.new(currentPos, target)
pet:SetPrimaryPartCFrame(newCFrame)
-- If the line below is commented (as well as the camera.CameraType = "Scriptable" which is not listed), it works fine)
camera.CFrame = CFrame.new(pet.PrimaryPart.CFrame.p) * CFrame.Angles(math.rad(-70), math.rad(0), math.rad(0)) * CFrame.new(0, 0, 20)
game:GetService("RunService").RenderStepped:wait()
end
end)
Kinda gravedigging, but I tried using the code you gave while also setting the camera type to Scriptable and trying it out in different orientations (even up side down) and it worked perfectly fine.
wait()
local mouse = game.Players.LocalPlayer:GetMouse()
local currentPos = Vector3.new()
local posPart = Instance.new("Part",workspace)
local mouseDown=true
mouse.Button1Down:connect(function()
mouseDown = true
while mouseDown do
game:GetService("RunService").RenderStepped:wait()
local target = mouse.Hit.p + Vector3.new(0, currentPos.y - mouse.Hit.p.y, 0)
currentPos = (CFrame.new(currentPos, target) * CFrame.new(0, 0, -0.25)).p
posPart.CFrame=CFrame.new(currentPos)
end
end)
mouse.Button1Up:Connect(function()
mouseDown=false
end)
Works perfectly fine for me though. Also, having to bind and unbind the function on every click seems a bit tedious.
That is considering you weren’t only talking about the second part.