I’m currently in phase 2 of a personal project creating a steampunk classic aero fighter game. And am now working on writing the core AI for dogfight. I have a several questions considering AI fighter turning into the player’s and chasing him at a close quarter range. However, AI has to follow certain rules while rolling and pitch (e.g., that says AI cant just Vinterp to another vector then throttle up).
And here’s the only mathematical solution I found to execute this AI task, and idk if there would be any better and easier/less expensive approach:
- get target’s world location and forward vector.
- get Ai’s world location and forward vector.
- make a vector that equals to: x = 0.0f, y = target.world.location.y - AI.world.location.y, z = target.world.location.z - AI.world.location.z;
- Then I will let the new vector cross product with target’s forward vector, and let the production be V_tgt.
- Then I will let AI’s up vector cross product target’s forward vector, and let the results be V_cur.
- Finally, the angle between V_tgt and V_cur should be the total delta roll for the AI to roll into the right orientation. And this angle can be solve by dot product of those normalized vectors, and then arccosine the results.
- Then a AI_Roll event with certain axis input will be casted to my EnemyFighter_Pawn blueprint, it will follow the physics I wrote per axis value from the events. Thus an angular speed will be applied to the fight_fuselage. Until the calculated angle from section (6) is less than a small value, AI_Roll events will have it axis input as zero and cast it to the EnemyFighter_Pawn.
- After reaching out to the right orientation, now its easy to calculate the right amount of pitch should be applied to the EnemyFight_Pawn. By using the same method, such that: evaluating the arccosine value of the dot production if forward vectors of target and the AI.
- Then the same AI_Pitch (custom) event along with its axis value (i.e., 1.0f) will be casted to the EnemyFighter_Pawn. It will add angular velocity relatively along the right vector direction to execute the pitch, until such angle is less than a small number.
Okay, That sounds tedious AF, but seemingly its working. The thing is, I don’t really think it is the right way to create AI in such horribly tedious manner. I believe there must be some API’s already written, or if anyone would kindly inform me of a better way to walk around this obstacle…
Essentially, AI needs to know two things: 1) how many degrees should I roll before I pitch? and 2) how many degrees should I pitch before I arrived at player’s 6?
PLEASE, if anyone would have a better and simpler approach! Please help!!
Thanks very much in advance.