I have a UI that clones a model locally and the model will follow the cursor. This works fine but the only problem I have is that the model gets stuck on the players camera somehow and when I move it off it always just inches back to the front of the camera. [See Below]
robloxapp-20230612-0056330.wmv (1.5 MB)
I would like to know if there are any steps I’m missing or things I’m not accounting for in my method.
Thanks for any help in advance!
local function getMousePosition()
local unitRay = mouse.UnitRay
local rayOrigin = unitRay.Origin
local rayDirection = unitRay.Direction
local rayLength = 300 -- Adjust this value based on your needs
local raycastResult = workspace:Raycast(rayOrigin, rayDirection * rayLength)
if raycastResult then
local x = math.ceil(raycastResult.Position.X / 0.5 - 0.5) * 0.5
local y = math.ceil(raycastResult.Position.Y / 0.5 - 0.5) * 0.5
local z = math.ceil(raycastResult.Position.Z / 0.5 - 0.5) * 0.5
Mouse_Position = Vector3.new(x,y,z)
return Vector3.new(x,y,z)
end
return nil
end
--keep the temp model updated with cursor if found
if Temp_Model ~= nil then print(Mouse_Position)
local Movable_Object = Temp_Model.PrimaryPart.Position
local formula = Mouse_Position - Movable_Object
Temp_Model:TranslateBy(formula)
end