Click and drag to rotate camera around something

Hi, all.
I want to achieve a system where the player can click their mouse and move it and this will then rotate the camera around an object.

So, would anyone know how to make this sort of system?
I’m listening!

Are you trying to make an inspect item system? I’m pretty sure it has something to do with viewportframes, and tweening, maybe.

It’s going to be used for a car view system.

Where a player can rotate the camera around a car and click buttons on the car that turn on lights, open doors etc.

1 Like

I’m trying to achieve the same thing you’re trying to achieve, there just aren’t any good tutorials out there.

1 Like

I ended up figuring something out using this script, forgot where I found it though. But I literally just used a script that rotated a circle based on where the player click and dragged it.

This might help you, but I’m not sure

local RotationBall = workspace.RotationBall

local A
local Button1Down = false
local AxisAngle = CFrame.fromAxisAngle
local VTOS = CFrame.new().VectorToObjectSpace

Mouse.Button1Down:Connect(function()
	if Mouse.Target and InDealer then
		Button1Down = true;
	end
end)

Mouse.Move:Connect(function()
	if Mouse.Target == RotationBall and Button1Down then
		if not A then
			A = RotationBall.Position - Mouse.Hit.p.unit;
		else
			local B = RotationBall.Position - Mouse.Hit.p.unit
			local Axis = VTOS(RotationBall.CFrame-RotationBall.CFrame.p,A:Cross(B))
			RotationBall.CFrame = RotationBall.CFrame * AxisAngle(Axis, Axis.magnitude)
			RotationBall.Orientation = Vector3.new(RotationBall.Orientation.X*0,RotationBall.Orientation.Y,RotationBall.Orientation.Z*0)
			A = B;
			if #workspace.CarPedastal:GetChildren() == 1 then
				workspace.CarPedastal:GetChildren()[1]:SetPrimaryPartCFrame(RotationBall.CFrame)
			end
		end
	end
end)

Mouse.Button1Up:Connect(function()
	if (Button1Down) then
		Button1Down = false;
		A = nil;
	end
end)
2 Likes

Can you explain how to set the script up. E.g what is “CarPedstal” and where does it go, or “InDealer”

So, InDealer is a bool value that checks to see if the player is in a dealership. This is a local script by the way. CarPedstal is a folder in workspace that contains a model of the selected car. When the script rotates the ball, it also rotates the model of the car with it.

This is done with this line of code:

workspace.CarPedastal:GetChildren()[1]:SetPrimaryPartCFrame(RotationBall.CFrame)

If you’re still having trouble, message me back

1 Like

Could I create a camera and set the SetPrimaryPartCFrame to the rotationball and when the rotationball rotates the camera will rotate too? or do I have to keep setting the camera CFrame to it?

The camera should stay in once place, only thing that should move is the rotation ball and the model it’s connected to.

1 Like

Ty, so if i connect the cam to the model will it rotate and update the cam position or will it just spin around?

Sorry for the late reply, you’ve probably tried this but I have no idea what it would do, haven’t tried it myself. I just have the camera stationary looking at the invisible sphere

:+1:, you could connect the camera and have it tweening to the new pos