Inspect Models (How to achieve 3d rotation with all axis using Vector2 (direction of mouse/MouseDelta))

Hello everyone, I post this one because I want to achieve this kind of rotation what involves the convertion of Vector2D from the movement of the Mouse (UserInputService:MouseDelta()) to 3D rotation.

An example of what I want to achieve is this: here is (which I think) Vector2D to 3D rotation with all three axis (X,Y,Z) from mouse movement (from Front Lines Roblox)

So I have my Inspect script but however the system only converts Vector2 into 2 axis (which is Y, Z) (you can see more in the script below or a demonstration here):

As you can see the system can only rotates on two 2 axis only so my goal here is to somehow, convert that same Vector2 direction (MouseDelta) to rotation on the X axis, as well as the other two.

I’ve tried to think to a way but couldn’t figure out (cause I suck at math :smiling_face_with_tear:), I’ve searched on forum for any topic like so for help but I haven’t seen anything yet (or maybe I just didn’t search hard enough). But anyways, if you guys can help me it would be very appreciative.

Btw here’s main code of the system, that involves in changing the the Y, Z rotation using the difference in mouse movement (per frame) of X, and Y

local X, Y, Z = model.X, model.Y, -5 -- just some starter values 
local diffX = 0
local diffY = 0
Connections.Render = RunService.RenderStepped:Connect(function()
		local Pos = CurrentCamera.CFrame *, 0, Z)
		self.Model:PivotTo(Pos * CFrame.Angles(0, X, Y)) -- only coverts Vec2.X = Y rotation, Vec2.Y = Z rotation, missing X rotation

local lastX, lastY = 0, 0
Connections.Input = UserInputService.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
		Camera.CameraType = Enum.CameraType.Fixed
		Connections.MouseMovement = Mouse.Move:Connect(function()
			local MouseDelta = UserInputService:GetMouseDelta()
			diffX = (MouseDelta.X) 
			diffY = (MouseDelta.Y)
			X = GetDirectionBasedOnDifference(diffX, X, Ratio)
			Y = GetDirectionBasedOnDifference(diffY, Y, Ratio)

function GetDirectionBasedOnDifference(Diff, Axis, Ratio)
	if Diff < 0 then
		Axis = Axis - 1 * Ratio
	elseif Diff > 0 then
		Axis = Axis - -1 * Ratio
	return Axis

apologies if this doesnt solve your problem, but there are a few topics related to this.

such as this, There are better topics related to your case, but heres just one i found.


He’s The G.O.A.T, THE G.O.A.T :sob::sob::sob::sob::sob::sob::sob::sob::sob:, I will definitely examine this code


Thank you, I found a related topic that solved my problem :+1:. It all comes down to key terms :sob::sob::sob::sob:

1 Like

Nice! Oh, and good luck on your game!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.