Hello. What I’m trying to make here is a banking(turning) function for my fighter plane.
How the plane is the setup:
Every BasePart in the model is welded using Motor6D’s to a MainBodyPart.
The whole model is unanchored
Parented to the MainBodyPart is:
BodyGyroLooking.Parent = BodyKit.CriticalStructure.MainBodyPart BodyGyroLooking.MaxTorque = Vector3.new(math.huge,math.huge,0) BodyGyroLooking.CFrame = BodyKit.CriticalStructure.MainBodyPart.CFrame
BodyGyroBank.Parent = BodyKit.CriticalStructure.MainBodyPart BodyGyroBank.MaxTorque = Vector3.new(0,0,math.huge) BodyGyroBank.CFrame = BodyKit.CriticalStructure.MainBodyPart.CFrame BodyGyroBank.P = 6000
BodyThrustC.Parent = BodyKit.CriticalStructure.MainBodyPart BodyThrustC.MaxForce = Vector3.new(math.huge,math.huge,math.huge) BodyThrustC.Velocity = Vector3.new(0,0,0)
A player sits in the seat and a LocalScript is cloned to the Players PlayerGui which is what is used to control the fighter.
The code that performs the movement and banking [Edited to reflect the changes I’ve made, Original Post Version can be found underneath the code segment]:
RSS.RenderStepped:Connect(function(Delta) if EngineActive then local MainBodyPart = script.Engines.Value.Parent.Parent.CriticalStructure.MainBodyPart local MousePosition = Mouse.Hit.p local Size = MainBodyPart.Size local Target = MainBodyPart.Position + ((MousePosition - MainBodyPart.Position).Unit * 100) local Left = MainBodyPart.CFrame * CFrame.new(-Size.X/2, 0, 0).p local Right = MainBodyPart.CFrame * CFrame.new(Size.X/2, 0, 0).p local CheckVar = (Target - MainBodyPart.Position).Magnitude local FCheckVar = MainBodyPart.CFrame * CFrame.new(0, 0, -CheckVar).p local RotationalVar = ((FCheckVar - Target).Magnitude / 8) local LeftPoint = (Target - Left).Magnitude local RightPoint = (Target - Right).Magnitude BodyGyroLooking.CFrame = Mouse.Hit MainThrust.Velocity = script.Engines.Value.Parent.Parent.CriticalStructure.MainBodyPart.CFrame.LookVector * 100 if LeftPoint < RightPoint and LeftPoint > RotationalVar and LeftPoint < 100 then print('Turning/Banking to the left') C = CFrame.Angles(0,0,math.rad(RotationalVar * 90)) BodyGyroBank.CFrame = CFrame.Angles(0,0,math.rad(script.Engines.Value.Parent.Parent.CriticalStructure.MainBodyPart.RotVelocity.Y * 10)) elseif LeftPoint > RightPoint and RightPoint > RotationalVar and RightPoint < 100 then print('Turning/Banking to the right') C = CFrame.Angles(0,0,math.rad(-RotationalVar * 90)) BodyGyroBank.CFrame = CFrame.Angles(0,0,math.rad(script.Engines.Value.Parent.Parent.CriticalStructure.MainBodyPart.RotVelocity.Y * 10)) else print('Flying Straight') BodyGyroBank.CFrame = MainBodyPart.CFrame * CFrame.Angles(MainBodyPart.Orientation.X,MainBodyPart.Orientation.Y,0) end end ---- OLD VERSION --- --[[if EngineActive then BodyGyroLooking.CFrame = Mouse.Hit MainThrust.Velocity = script.Engines.Value.Parent.Parent.CriticalStructure.MainBodyPart.CFrame.LookVector * 100 BodyGyroBank.CFrame = CFrame.Angles(0,0,math.rad(script.Engines.Value.Parent.Parent.CriticalStructure.MainBodyPart.RotVelocity.Y * 10)) end]] end)
The 1st problem is when I go turn in any direction and then move forward in a straight line, the banking doesn’t/takes a very long time to realign itself to a straight position.
The 2nd problem is when I 180 the fighter and start going in the opposite direction. Instead of following the bank, the aircraft in the opposite direction once the turn has been completed
I can provide more information if necessary.
I would divide up the problems into individual posts, but they are too closely related to each other I believe.
Thanks for any help on how to fix them!
EDIT 1: Using :ToWorldSpace() changes nothing. The same problem is produced.
EDIT 2: Changing the multiplication of the the RotVelocity.Y still produces the same problem, if not a quicker one.
EDIT 3: Using an integer as a replacement for using RotVelocity.Y still brings the same problem when you turn the aircraft in the opposite direction
EDIT 4: I have a feeling it is because of the BodyGyroBank.CFrame is not relative to the part?
EDIT 5: Even when using a different system that uses a set value as the angle, the same problem of the aircraft rolling even when flying straight continues.
EDIT 6: I’ve come to the conclusion that the problem has something to do with the orientation and its relativity to the world instead of the part. Why it continues to rotate I do not know.
EDIT 7: I should have probably mentioned this, but I have a BodyVelocity that moves according to MainBodyPart.LookVector * 100.
EDIT 8: Edited the code to reflect the changes I made.
EDIT 9: Code has changes that determines whenever the aircraft is turning right,left or flying straight.