Body Angular Velocity changing the z axis when trying to change the x axis

I am making a plane but for some reason when I try changing the x axis changes the z axis only.
If I have no torque on the z axis it will stop working.

local function getoffset()
	local centerX = Camera.ViewportSize.X/2 -- center of the screen (x axis) in pixels
	local centerY = Camera.ViewportSize.Y/2  -- center of the screen (y axis) in pixels
	local xOffset = (centerX - Mouse.X)/(Camera.ViewportSize.Y/2) 
	local yOffset = (centerY - Mouse.Y)/(Camera.ViewportSize.X/2) 
	local Offsets = {xOffset, yOffset}
	return Offsets
end

-- It uses bind render step to find the mouse position
BodyAngVel.MaxTorque = Vector3.new(1,1,1) * math.huge
local MouseOffset = getoffset()
BodyAngVel.AngularVelocity = Vector3.new(MouseOffset[2],MouseOffset[1],0)

Any help would be greatly appreciated.

I tried setting the parts orientation on the z axis to 0 but it still does not work.

BodyAngularVelocities use a system with two parts

The vector which is provided in the AngularVelocity property is the axis it rotates about
For example:
If you provide the vector (0,1,0), itll rotate around the global Y axis

If you provide the vector (1,0,0), itll rotate around the global X axis

The speed at which it rotates is given by the magnitude, or length of the given AngularVelocity vector
So a vector (0,1,0) would move 1 radian per second around the y axis, while the vector (0,100,0) would move 100 radians per second around the y axis

Given this information, you can generate some simple code using the rightvector and upvector of the airplane to find the global axis which it should rotate about:

local function getoffset()
	local centerX = Camera.ViewportSize.X/2 -- center of the screen (x axis) in pixels
	local centerY = Camera.ViewportSize.Y/2  -- center of the screen (y axis) in pixels
	local xOffset = (centerX - Mouse.X)/(Camera.ViewportSize.X/2) 
	local yOffset = (centerY - Mouse.Y)/(Camera.ViewportSize.Y/2) 
	local Offsets = {xOffset, yOffset}
	return Offsets
end

-- It uses bind render step to find the mouse position
BodyAngVel.MaxTorque = Vector3.new(1,1,1) * math.huge
local MouseOffset = getoffset()
BodyAngVel.AngularVelocity = airplane.CFrame.UpVector*MouseOffset[1] + airplane.CFrame.RightVector*MouseOffset[2]

(Note that this is assuming you want the action of moving the mouse side to side to move the airplane side to side, if you want the action of moving the mouse side to side to roll the airplane, simply change UpVector to LookVector in the first component)

2 Likes

Thank you for the help but for some reason it slightly tilts the plane but it will suffice.