I'm a mechatronic engineer and was able to mostly follow along with this. I know it would be extra work on your part, but explaining the vector math with diagrams would make this a lot easier to understand for more casual (or younger) players. This is a great video though. I'd be interested to watch you play through one of the campaigns.
i made a proximity fuse version for air targets: function Update(I) target_position = I:GetTargetInfo(0, 0).AimPointPosition target_velocity = I:GetTargetInfo(0, 0).Velocity proximity_radius = 10 -- Adjust this value to set the proximity radius time_threshold = 2 -- Adjust this value to set the time threshold for detonation after passing the target for t = 0, I:GetLuaTransceiverCount() - 1 do for m = 0, I:GetLuaControlledMissileCount(t) - 1 do missile_info = I:GetLuaControlledMissileInfo(t, m) missile_position = missile_info.Position missile_speed = Vector3.Magnitude(missile_info.Velocity) target_distance = Vector3.Distance(target_position, missile_position) target_vector = Vector3.Normalize(target_position - missile_position) relative_speed = missile_speed - Vector3.Dot(target_vector, target_velocity) lead_factor = 1.5 -- Adjust this value to control the amount of lead prediction = target_velocity * target_distance / relative_speed * lead_factor point = target_position + prediction I:SetLuaControlledMissileAimPoint(t, m, point.x, point.y, point.z) -- Check if the missile has passed the target and exceeded the time threshold if target_distance time_threshold then -- Detonate the missile I:DetonateLuaControlledMissile(t, m) I:LogToHud("Missile detonated at proximity radius and time threshold") end end end end
I usually find not worth the trade of from "normal" to lua, due to the place and price used by general processing power cards. But I still use lua for special kind of missile. For exemple I got a huge missile how purpose is just being a lump of metal with a heck of health to distract CWIS, and circle (above or under the target, depending if it's a aircraft or a boat). And lua is pretty much the only way to do that.
Looking forward to all those advanced guidances. Since those missiles are going so straight, you will need less fins freeing up space there as well. When I tried to do this a couple years ago I had no idea about these helper functions and little knowledge of vector math which resulted in me giving up on LUA. Thanks for showing me that it's very achievable and useful so I'll take a crack at it again.
Great video! The are two things that would be great to have tutorials on. They both stem from FtD targeting and guidance systems not taking into account water drag (for crams) nor gravity's altitude dependence. The first is tutorial is for semi ballistic or high altitude launched lau glide 'bombs' with the most difficult type effectively being a drone that acts as a interceptor decoy while getting into a good position and heading relative to the target for the most effective use of its payload of short range missiles or mines (example 1: A glide bomb with payload of short range one-turn single pixel AA missiles to set off enemy flares and get the AA missiles behind an enemy jet which is too far away for accurate vehicle based detection. Example 2: Glide bomb that looks at life-time vs time-to-target and computes whether to glide or dive, taking into account that the gravitational field strength and air resistance varies with altitude.). The second tutorial would be using lua to aim CRAM cannons
Good video, but that's not the right way to calculate the closing velocity of missile and target. First you should subtract target velocity from missile velocity, then do the dot product: the way you did it you overestimate the closing velocity as you assume the missile is heading straight for the target, and for fast targets requiring a significant amount of lead that can result in enormous errors. You got very lucky with your dummy target, as the lead error introduced by its acceleration (which would make the missile lead too much) is of opposite sign to the error introduced by your LUA code (which would make the missile lead too little) so the total error ends up being small. Also the vanilla prediction guidance module is just broken: looking at the decompiled code, it doesn't even try to take the target's velocity into account to determine time to impact, it just does relative distance divided missile max velocity.
I think you would end up with major overcorrection as the missile turns towards the target. Your missiles would arc in the opposite direction as they approach and defeat the purpose. They would have the disadvantages of guided and non guided. I even go a step further away from your suggestion by hard coding my missiles’ average speed. This will prevent overcorrection as it turns into the target or speeds up. Near the target, I use the real speed.
@@scottwright7177 you'd think wrong, "my" suggestion is an alternative formulation of proportional navigation and that's known to be optimal within its constraints. If you don't trust the math, try your missile against a target with a different acceleration profile, for example the same test target circling at some distance from the launchpad instead than right around it. Or just try agains a sufficiently fast target that moves in a straight line, you'll consistently see your missile fall behind it.
This might be late but i wanted to thank you for this tutorial, i am working on a new Missile AA platform and will use your code for the missiles, might add some other stuff later on
where do you find the terms to put in? is it under help? i have pretty much treated lua as a pandoras box full of daemons and mischief hat i should just leave alone.
where's part 2 a long time ago I heard someone made LUA torpedoes that went under ships and attacked directly from beneath basically the opposite of the one "like artillery" you mentioned
Hey Scott, thnx for this video. Pretty please if you can do a next video on this subject, especially for "rain from above" code that you have on Pastebin. Thank you!
Part 2 when? XD Am currently trying to figure out how to take gravity into account for an orbiting missile. This vid certainly refreshed my memory on stuff like game tick length.
I'm sorry, everyone, for the silence on FtD videos. I'll see if there is any time to get back into the game and finish some of what I started. I've been busy... really busy. I mean I've been helping start up a company, moving, finishing my Master's, and now raising a daughter. It's been over a year since I've touched FtD.
@@scottwright7177 I need to use a LUA box to detect the health of a construct, the nearest one if it's not specific or an indexed one if possible. Then I need it to trigger a complex controller for me. Is that possible? I know you can get the Health Fraction of a friendly but if there's multiple of them can i choose which. Do you have discord by chance?
from a dev standpoint (not math oriented) i would say your explanation are close to perfect :) i would just have renamed `t` to `transmiter` and `m` to missile for readeability but otherwise your explaination were realy nice
Yeah, have a list of missile timers outside the Update function that follows the same index patterns as the missiles. Check if the timer is 1-2 seconds before using the code.
Is there a way to code a lofted trajectory as in fly at 800m then when closing in come down and strike from above? I noticed the older code to do this is fairly broken
I tested medium & small missiles vs fast over 150m/s small planes keep missed only few hit not good vs fast small planes only good vs big slow plane/airship under 110m/s & only worked small missiles vs under 110m/s small planes. Best laser & 1000m/s ballistic vs small fast planes over 150m/s. I used EMP small missiles vs under 110m/s small planes go BOOM! AI dead is awesome lol.