Answered by
4 years ago Edited 4 years ago
I found a solution
I created a variable called roll
and incremented it by 1 or -1 when A or D is pressed. If roll ever comes equal to either 360 or -360, then it is reset to 0. I then multiplied this angle by the BodyGyro CFrame.
01 | local UIS = game:GetService( "UserInputService" ) |
02 | local player = game.Players.LocalPlayer |
03 | local mouse = player:GetMouse() |
04 | local shipPart = workspace.TestShip.PrimaryPart |
13 | game:GetService( "RunService" ).RenderStepped:Connect( function () |
15 | shipPart.BodyVelocity.Velocity = workspace.CurrentCamera.CFrame.LookVector * SPEED |
16 | shipPart.BodyGyro.CFrame = CFrame.new(workspace.CurrentCamera.CFrame.Position, workspace.CurrentCamera.CFrame.Position + workspace.CurrentCamera.CFrame.LookVector) |
18 | if roll = = - 360 or roll = = 360 then roll = 0 end |
19 | shipPart.BodyGyro.CFrame = shipPart.BodyGyro.CFrame * CFrame.fromEulerAnglesXYZ( 0 , 0 , math.rad(roll)) |
21 | if UIS:IsKeyDown(Enum.KeyCode.W) then |
22 | SPEED = math.clamp(SPEED + ACCELERATION, 0 , MAX_SPEED) |
23 | elseif UIS:IsKeyDown(Enum.KeyCode.S) then |
24 | SPEED = math.clamp(SPEED - (ACCELERATION * 2 ), 0 , MAX_SPEED) |
25 | elseif UIS:IsKeyDown(Enum.KeyCode.A) then |
27 | roll = roll + rollFactor |
28 | elseif UIS:IsKeyDown(Enum.KeyCode.D) then |
30 | roll = roll - rollFactor |
If someone else thinks they have a better solution please don't hesitate to let me know! Thanks