Unity Combat Space Sim: Basic AI and Missiles

Опубликовано: 14 Май 2026
на канале: Why485
6,142
35

This has no code in common with the Freespace simulator I posted about last week. This was made completely from scratch starting last weekend. The only thing it shares with it is the Freespace models which I am using because they look cool and I don't want to take the time to make my own for now.

I'm really proud of this. There's a lot in here that I've never done before and it's set up in such a way that a legit game could actually come out of this. Usually I throw things together quickly because I have a very specific goal I want to demo or something I want to try. This is the first thing I've done that isn't like that.

I could go on for a while about why that is, so instead I'll just list off features this has so far.

Rigidbody physics based ship handling
Separation of components by function
Drag and drop ship loadouts with the inspector
Primary and secondary weapons
Bullet and missile hit detection
Missiles can be shot down
Many targeting modes/keys from next ally to nearest hostile
Two separate factions and one neutral faction
Time and angle based missile locking
Homing missiles with many parameters that affect missile handling
Simple heads up display
Target box which shows target HP and distance
Ships are piloted by "pilots" of which can either be player or AI
AI that is extremely accurate in flying and aiming their physics-based ships
AI ships follow all the same physics as players do
AI ships control their ships with the same exact commands players do

AI is what I started working on last night. It was a bit of adventure with a lot of failed starts. The problem I was having is that because of the physics based nature of the ships, it's hard to just tell the AI to turn to a specific place without either overshooting it or lagging behind it.

After some thought, I decided to implement a PID controller. This turned out to be the magic formula. With a tuned PID controller, the AI is now frighteningly accurate in their control of the ship, more so than a player would be. I might tweak that a little later on but now that I'm confident that the AI can fly their ships, I can move onto more complex behaviors such as flying waypoints and smartly engaging targets.