I created some plane AI stuffs like a simulation as a dogfight scenario using some simple gyro and some stuffs.
But the banking using bodygyro is acting weird when the plane turns around while flying upward, flying downward and turning works fine.
I tried inverting the bank numbers, but it still acts the same even when flying downward.
Here is part of the code that controls the banking if you need to look into it
The plane is using 2 BodyGyro
The first one controls where it look at.
with MaxTorque inf, inf, 0
The second one controls the banking of the plane.
with MaxTorque 0, 0, inf
CS:GetInstanceAddedSignal("Engine"):Connect(function(Bomber)
if Bomber == Object then
--TweenS:Create(Center.Propeller, TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {PlaybackSpeed = 1}):Play();
--Center.Propeller:Play();
while CS:HasTag(Object, "Engine") do wait(1/10);
BodyVelocity.Velocity = Center.CFrame.lookVector*Plane_Speed.Value;
BodyBanker.CFrame = CFrameAngles(0, 0, mathrad(Center.RotVelocity.Y*40));
end;
end;
end);
It sounds like you have a frame of reference issue. I’ll use a simple example to explain why I think this is the issue.
If you have a clock ticking normally, you would say that the hands move clockwise. But if you looked at the clock from behind, you would see the opposite - counterclockwise. Now this is where people get confused since they imagine a clock that has numbers. Just imagine it without numbers.
For your plane, your bank gyro is acting in a plane, and it is rotational by definition. I’ll draw a picture to make this a bit more clear.
The red arrows are your plane travelling up/down. Now imagine it is turning left - the rotational velocity should be “left” too. But really, this is an orientation you are setting in the gyro, so left is arbitrary. I will refer to it as “left” for now, but we’ll soon see why this is flawed.
If you compare the rotational velocity and apply it to the Z-axis, which is what you are doing in your code, you will see that the plane rotates clockwise! This is opposite of what you intended. Now if you look at the plane moving downward, the rotational velocity is the same relative to itself, but if you apply this to the Z-axis again, the plane rotates counterclockwise! So it doesn’t matter if you assign left or right, or switch negatives, etc… This is fundamental to the coordinate system. You have to assign the negative when the plane is moving downwards, or the opposite, in order to achieve the desired banking. If your downward banking works, then assign the upward as negative and it should work out.
Hope this helps. Sorry for the late reply, I was writing this yesterday and got held up. Hopefully you’ve solved it by now but if you haven’t, I hope this helps with the issue.