Rotate actor only using Pitch and Roll

I am working on an AI for a fighter jet and using find look at rotation will rotate the plane in the yaw too which looks unrealistic and bad. so is there a way to rotate an actor twards a point only using pitch and roll like a fighter jet would?

Hey @RHIJZY

You can lock rotation and movement axis.

Select the SkeletalMesh, StaticMesh, Capsule or whatever your root component is, and modify its constraints.

image

You can also break the rotator calculated by Find Look At Rotation and set the Yaw to 0 before setting the new rotation.

1 Like

I already tried it and it doesn’t work. instead of compensating the yaw rotation with roll and pitch it rotates normally in roll and pitch and doesn’t rotate in yaw which makes it not look at the target. I am trying to make a jet plane AI basically.

I don’t think this is supported as simple builtin options. You’ll have to do it yourself.

I’d say the response depends alot on how your plane is implemented, and also the AI navigation.

Afaik the existing navigation implementation(s) do not support 3D space movement. Are you using a custom nav system with a custom path following component, or simply controlling movement directly without pathing ?

Also the plane movement, are you using simplistic Floating/FlyingPawnMovement, or moving the pawn directly in Tick, or are you using more complex physics-based movement such as ChaosVehicle with Wings/Aerofoils setup ?

If you’re using nav systems, afaik there are two places you can override to implement the behavior you want. Either override function FollowSegment from path following component, there you can modify how the inputs are sent to the MovementComponent. Default implementation sends a basic input vector that directly points to the destination, regardless of how the source currently is. Instead, you’d want to send appropriate inputs to roll the plane and pitch it, in order to achieve desired movement. Alternatively, leave the path following component alone and override RequestPathMove or RequestDirectMove from your plane’s movement component. In this function you’ll receive the desired direction vector passed from the path following component, so you can do the same thing and convert that desired direction into fake roll+pitch inputs. (obvious easier said than done)

If you’re not using nav systems, I assume you’re controlling AI with Tick and variables, calling directly SetPosition and SetRotation or equivalents. In that case it’s not really different, but you’ll have to modify the rotation code to integrate rolling/pitching instead of directly relying on the LookAtRotation.


To illustrate a bit, I set up a simplified example.
First step, I try to reproduce your current situation. I made very simple level with target locations and a plane that loops through these locations.

This is most simplistic, with the following code (not detailing targets code here)

image


Now second step is to turn this into something somewhat more realistic, ie. tilt the plane towards desired direction, and make the turn rate dependent on current tilt amount. The more tilted = the faster it turns.

So I cut function CalcRotation into two sub functions, first will calculate the Roll and second will calculate Yaw (and Pitch) based on Roll amount.

image

To calculate roll I look at where the target is - if it is in front no need to roll, if it is on my right I roll right, else I roll left.

Then I rotate the yaw (and pitch) with an interpolation speed that depends on roll amount.

This is nowhere near top quality, nor ready for 3D, but hopefully should give you some ideas to explore. In true 3D the calculations will be more complex and you’ll probably want to stick to Quaternions. For a more robust approach you’ll definitely want to implement movement in the MovementComponent, taking Rolling and Pitching as movement inputs. Then making the AI becomes a matter of calculating which inputs you need to simulate in order to achieve desired movement. But all of that’s still roughly in the same vein as above.

4 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.