From The Depths
Civvy Jul 16, 2018 @ 2:04pm
How to program submarine AI?
RIGHT! So, I've got the hull of a submarine, I've given it torpedoes and an AAA gun-- now all that's left to do it get it to act like a sub.

So, I'm faced with a few questions, and I need ya'll's help!

1. What would be best for turning? Should I use turning thrusters, or should I use a rudder?

2. I want the submarine to close in on an enemy ship to torpedo it, but run away when it comes too close, while still firing its back torpedo tubes. How do I program the control blocks to do this?

3. Do I need a PID for any of this?

4. How do I control the altitude of the ship, and how do I use the hydrofoils to do it, or do I use them at all?

5. How do I set up the air pumps in the ship to raise and lower the hull as needed? I don't want to ship to go too deep, but I don't want it very shallow either, but some of those islands can be shallow!

Thanks in advance for anyone who's made a sub n' wants to help. It's very much appreciated!
< >
Showing 1-3 of 3 comments
FourGreenFields Jul 16, 2018 @ 2:09pm 
1. I'd use both. Rudders are easily shot off, but quite powerfull.

3. No, but it'll probably help a lot. Especially for depth-keeping.

4. Several options. I think there's a hydrofoil-altitude setting for PIDs, which is probably best for this.

5. PIDs can control airpumps. Allthough that's not going to make much of a difference (but still better than nothing).
GlutenFreeGamer Jul 23, 2018 @ 2:16pm 
I built a few submarines a while back; it's very challenging. I learned the following....

There's two types of submarine (boat). Static dive, and hydro.

Hydro is much easier; point the hull down, use forward thrust, and the water pushing over the top of the boat will force the sub down FAST. Automated control blocks can be used to control hydroplanes (the logic is "if depth is greater than 50m, dive plane force boat to angle up, if depth is less than 40m, dive planes force boat to point down). A simple sub with a few torpedos that lingers between 40 to 50m depth is hilarious fun, and nigh on uncatchable by the AI. --the catch is the boat has to keep moving to stay submerged. (This is actually how early german wwII u-boats worked).

Dynamic dive (i.e. go up and down on the spot) is MUCH harder to accomplish. A huge empty room with a hole in the bottom and an ACB connected to an air pump will simulate a balast tank; when flooded, the extra weight of the water will make the boat sink, when filled with air, the boat rises. You'll need a very well balanced boat, and a lot of experimentation to get the room the right size. If you're super-clever, you can put one front and one back to control trim AND depth.

As for your "attack patterns", edit the properties of the naval control computer card; You'll figure this out fairly easily. You're looking for a narrow attack angle, high minimum engagement range, and even higher re-engage range to get the sub to dart in, shoot torpedos, then turn around and leg it out of there (and repeat). Don't forget to setup the weapon computers to suit, as well.

It's definitely doable, but it's real challenge to get it done. Plenty of empty space / false floors / false rooms to add ballast ((lead weight or pumped air)) to get the balance right and the extra components subs need are you friends here.

The upshot is a single working submarine is game-breaking in the neter campaign. After 40m, most shells are so slowed down by water resistance, they just sort of run into the hull and go "dink", roll off, and sink to the bottom, and true torpedos can sink almost anything.
GMC Jul 24, 2018 @ 4:53pm 
Originally posted by Civvy:
1. What would be best for turning? Should I use turning thrusters, or should I use a rudder?
If you don't have a rudder, the AI (and ship controller) assume that you cannot turn. But It's a good idea to add bow thrusters as well, as rudder-based turning depends upon speed.

Originally posted by Civvy:
2. I want the submarine to close in on an enemy ship to torpedo it, but run away when it comes too close, while still firing its back torpedo tubes. How do I program the control blocks to do this?
That's controlled through the Naval AI card.

Originally posted by Civvy:
3. Do I need a PID for any of this?
Yes; definitely for altitude and maybe for pitch as well.

Originally posted by Civvy:
4. How do I control the altitude of the ship, and how do I use the hydrofoils to do it, or do I use them at all?
You can control either hydrofoils or air pumps via a PID to maintain altitude (i.e. depth). Air pumps have the advantage that they work even if the sub is stationary. If you rely upon hydrofoils, the sub will either float to the surface or sink to the bottom (depending upon density) if it's not moving fast enough.

You can't use hydrofoils for both altitude and pitch; if you use air pumps for altitude, you can control the hydrofoils with a PID to maintain pitch (but you need to disable reverse movement via the Naval AI card; the PID doesn't understand that it needs to reverse the hydrofoil angle if you're moving in reverse).

If you decide to use hydrofoils for altitude, you should try to achieve neutral buoyancy, i.e. the sub should either barely float or barely sink without any propulsion. The hydrofoils should just be tipping the balance, not constantly pulling the sub upward against its weight or downward against its buoyancy. If you aren't controlling the air pumps via a PID, you can manually set their buoyancy fraction to achieve this (i.e. you don't need to add a ton of lead blocks).

Originally posted by Civvy:
5. How do I set up the air pumps in the ship to raise and lower the hull as needed? I don't want to ship to go too deep, but I don't want it very shallow either, but some of those islands can be shallow!
A general-purpose PID controlling air pumps. Set the altitude (which should be negative) via a test stimulus. The AI won't attempt to control altitude; you just have to set it manually in the PID (and change it if you need to navigate shallow waters).
< >
Showing 1-3 of 3 comments
Per page: 1530 50

Date Posted: Jul 16, 2018 @ 2:04pm
Posts: 3