How would I make this type of mouse?

So I’m trying to make this type of mouse just like in SCP 3008 But I have no idea. Would I need to add 2 mouses or use tween and stuff to move it? this is the example:

3 Likes

It looks like the way they did it was by casting a ray out, finding which Model the result belongs to, and then doing Camera:WorldToViewportPoint() on the model’s primary part. The cursor is then set to be around halfway between the mouse position and the position returned from the function. Here’s how it may look:

function testResult(result)
	local part = result.Instance:FindFirstAncestorWhichIsA("Model");
	if not part or not part.PrimaryPart then 
			-- Make sure the Part is in a Model, and the
			-- model has a primary part
		return false;
	end
	
	local point = camera:WorldToViewportPoint(part.PrimaryPart.Position);
	if point.Z < 0 then 
			-- Make sure the point is in front of the screen
		return false;
	end
	
	return true, point;
end

RunService.Heartbeat:Connect(function(dt)
	
	--Simple way to get the mouse hit position
	local mouseLocation = UserInputService:GetMouseLocation();
	local mouse = camera:ViewportPointToRay(mouseLocation.X, mouseLocation.Y);
	local result = workspace:Raycast(mouse.Origin, mouse.Direction * 20);
	
	if result then
		local pointTest, point = testResult(result);
		if pointTest then 
			-- The point is part of a model and the mouse is on screen,
			-- so do fancy halfway calculations.
			point = Vector2.new(point.X, point.Y);
			local newPoint = mouseLocation + ((point - mouseLocation) / 2);

			frame.Position = UDim2.new(0, newPoint.X, 0, newPoint.Y);
		else
			-- If the point isn't part of a model or is behind the screen,
			-- default to the mouse location.
			frame.Position = UDim2.new(0, mouseLocation.X, 0, mouseLocation.Y);
		end
	else
		-- If nothing was found, default to the mouse location.
		frame.Position = UDim2.new(0, mouseLocation.X, 0, mouseLocation.Y);
	end
end)

robloxapp-20210815-1625097

Obviously, this doesn’t account for the interpolation, but it’s a pretty good start.

7 Likes

Question when Ive tried setting up the variables for the missing ones like camera and frame but which would I put for them?

camera would be workspace.CurrentCamera and frame would be whatever ImageLabel / Frame instance you want to use for the fancy cursor. I personally put this script under a ScreenGui and indexed the frame directly, via frame = script.Parent.Frame

Thank you and also where can I place the script?

1 Like

To avoid complexity, I’d recommend putting it under whatever ScreenGui you’re using for the fancy cursor.

how would i position the frames position to be on the mouse? mine is a little under the mouse

Set the AnchorPoint of the frame to (0.5, 0.5)

mouse it still doesnt place it correctly

Oops, make sure the ScreenGui you’re using has IgnoreGuiInset set to true.

1 Like

Hello, it may have been a long time since this was made but i as wondering why it keeps locking on the HumanoidRootPart and how to fix it. Can you help me?