I’ve set up a jet with a top-down camera to constantly fly forward and steer toward a point under the mouse which works great - it turns in the direction I want. The camera moves with the jet and flies to wherever the cursor is (shown with the red debug sphere):
I’m trying to get the mesh to roll either left or right, depending on how hard the turn is. I’m thinking that I could feed the difference between the current rotation and the target rotation (where the curser is) of the jet into the roll rotation of the mesh. The problem is that I can’t seem to find out how to get this to work in the way that I want.
Ideally what I think I need to do is get a a value between -1 & 1, being the difference between the two angles, which I can then convert to rotation of the mesh.
A value of -1 would be a full roll left, and 1 would be a full roll right
This is what I have so far. Would appreciate any help:
Once you start banking the plane ( roll ), you have to take all parts of the rotation into account, not just work with Z. Unless you want to wait until the plane is totally flat again each time.
I haven’t tested it, but something like this is along the right lines I think:
I start by converting the angles to a 360 bearing and subtracting the difference. If the difference is greater than 200 degrees, I know I’ve ‘overlapped’ (i.e. if the jet has a bearing of 30 degrees and the angle to the cursor is something like 330).
In that case, I subtract 360 from the roll angle so it can keep turning left. I do the opposite for when turning clockwise, adding 360 to the roll amount. It’s not particularly elegant but it works perfectly.
My only concern is that this runs every tick. Should I be concerned about performance?
I should clarify that the plane was yawing fine and pointing toward the cursor. The issue I was trying to fix was getting the jet to bank with the turns. Again, thanks for your help.
It looks ok for tick. Just take a look at your frame rate with it on and off, it should always be 120 in an otherwise empty map ( or whatever your default is ). If something’s too heavy, you’ll see it.