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 ), 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 * CFrame.new(0, 0, Z)
self.Model:PivotTo(Pos * CFrame.Angles(0, X, Y)) -- only coverts Vec2.X = Y rotation, Vec2.Y = Z rotation, missing X rotation
end)
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)
end)
end)
function GetDirectionBasedOnDifference(Diff, Axis, Ratio)
if Diff < 0 then
Axis = Axis - 1 * Ratio
elseif Diff > 0 then
Axis = Axis - -1 * Ratio
end
return Axis
end