Make an AI aircraft's nose look at player aircraft

My game involves an aircraft battle in which I want an AI aircraft to fire at the player’s aircraft. The aircraft moves by adjusting its Roll and Pitch for changing altitude and taking turns (No Yaw here)

How will I determine the correct values for Roll and Pitch in Unreal Blueprint to make the nose of the aircraft look at the other aircraft? I think a good starting point here will be the “Find Look at Rotation” node.

Yes use “look at” node, however only this will make make space dogfights (where crafts can freely rotate and maintain velocity). Making ai for aerial dogfight is not that easy.

You need to track where enemy want to point, and where it can (due to air drag velocity and inertia). Then slowly interpolate rotation. And this does not account for loss of speed or lift force.

Maybe ask google or chatgpt (and then google). I suggest chatgpt first, so it gives you some answer (not necessary correct), but you will get keywords, and feed those to google for better answers.

Actually, I need space dogfights only (I should have mentioned it but thought that people might relate better to aircraft and not spaceships).

In any case, ChatGPT did not provide any sensible answers and I can’t seem to describe the problem well enough to google to get any good solution or video (or maybe there isn’t any good answers on google).

It’s definitely gonna be similar to this

Maybe use the “distance to”, i haven’t messed with any Flying characters yet but you’d have to do something other than AiMoveTo because there’s no mesh to navigate on unless you add an invisible plane ( in the geometry sense ) but that’s probably long term a bad idea for some reason i don’t know

there’s also a node for determining which way an actor is facing and another to get a specific component if it has to be the tip of the aircraft

Never made a flying game sorry if this advice is useless but you appear newer to the forums and unreal so this should give you stuff to type into google/gbt
my apologies if your not new/newish

1 Like

For space dogfights, first decide if its physics based craft, or you use set rotation and move instead.

Physics based craft is much harder to do, but it can interact properly and bounce off things like asteroids.

For just rotating, use look at rotation, then rinterpto to rotate craft. However watch for gimbal lock and pole singularities. So you may be forced to use quaternations.

With physics based, well it is quite complicated. You need to learn about thing called STEERING and some non linear algebra. Or use chat gpt then pick up keywords and as google for solutions. Or use damping but that thing defeats reason for physics, as it makes pushing slowing etc unrealistic.

On top of it all you want decent AI to use it. Like path planing, finding where to fly to intercept (together with inertia and acceleration).

But depending on what type of gameplay you want (arcade or more simulation like). You should first do normal (non physics) motion, then make it fun (very important, just grab Everpsace 2 demo, imo good game but they did not made flying fun, so everybody thinks it is just boring game, while flying model is not fun).

1 Like

hi ,this sounds interesting.I would try to do it tomorrow.if I got lucky I would share the code.

1 Like

Thanks for the help @Nightwolf483 and @Nawrot. However, those solutions didn’t work. I think the biggest challenge here is that I can’t directly set the yaw and need to play around with Pitch and Roll only.

Anyway, here’s some more details.

The movements for Spaceships have already been done (because the player gets to control one too).
There are three movement controls - Thrust (w key), Roll (Mouse X), and Pitch (Mouse Y). They are handled by applying linear velocity or torque to the spaceship.

But now I want the AI to be able to control the spaceship (and fire at the player too). So it will call those same thrust, roll, and pitch events directly (all of them have action values too for controlling intensity).

The idea that came to my mind was that maybe I could figure out the exact Pitch and Roll required for turning to the desired location, I can call the Pitch and Roll function accordingly until that rotation is reached.

In any case, I’ll welcome any suggestion as long as it makes my AI spaceship fire at the player.


Apologies for the incomplete information. Also, it’s great to see such a welcoming forum community (I don’t see that very often :slightly_smiling_face: ).

Thanks, i know i see some posts that are just Dead when the person has a simple problem but doesn’t know how or what they are asking necessarily

And I’ve been there so I try to help on the posts that i can, and usually try and give a picture example cuz words are confusing if you are primarily a visual or demonstration learner ,

so we all learn something or it gives an idea of how to do it better/differently, for example i just learned I’m gonna have to learn what the heck are quaternations


the pitch and roll.if controlled separately,seems worked well.but if controlled both at the same time,they don’t work well.still needs a lot adjustment.
The effect I got so far:

BP:


1 Like

Thanks for your efforts. This gave me the desired results.

It indeed needs a few adjustments but the basic logic has been figured out which is just what I needed.

Thanks again for helping me figure this out.

1 Like