From The Depths

From The Depths

Not enough ratings
Basic Top-Attack Lua Missiles
   
Award
Favorite
Favorited
Unfavorite
Blueprints: #blueprint, Lua, Missile
Tags: fortress
File Size
Posted
13.820 KB
26 Apr @ 5:45pm
1 Change Note ( view )

Subscribe to download
Basic Top-Attack Lua Missiles

Description
Basic Lua script for top attack missiles. It is made to be as light as possible, so it doesn't have a lot of bells and whistles. Perfect for Lua missile spam without being too laggy. It has basic prediction guidance and the option of spreading the missiles out over a large area for resistance against CIWS and interceptors.

This was made for the Chorus CC but I'm uploading it to the workshop out of popular demand.

Here is the script itself if you don't want to go through the hassle of downloading the craft:

-- CONFIG OPTIONS --

turnrate = 50
--put the missile turnrate here
--it is a really good idea to lowball your turn rate

--turnrate controls how aggressively it handles the top-down attacks
--low turnrate = less topdown, more turnrate = more topdown

padnames = "the"
--the name of EACH CONTROLLED MISSILE LAUNCH-PAD
--remember to leave '' around the name 'like so'

maxspread = 500
--the missile spread distance in meters
--this is evasive spread, not aimpoint spread

mainframeindex = 0
--leave this at 0 unless you have multiple AIs
--afaik index goes from 0 up with the priority of mainframes (prio 500 is 0, prio 100 is 1, prio -300 is 2, etc)
--it could also be the order of placement, idk for sure


-- END OF CONFIG --


function Update(I)
I:Log('tachyon6271 was here')
for a = 0, I:GetLuaTransceiverCount()-1 do

if I:GetLuaTransceiverInfo(a).CustomName == padnames
then --only control missiles if they match the launchpad name

for b = 0, I:GetLuaControlledMissileCount(a)-1 do
-- going through each missile (provided they match the name)
-- and telling them where to go

local missileinfo = I:GetLuaControlledMissileInfo(a, b)


turnrate = Mathf.Clamp(turnrate, 0, 70)
local aimpoint = I:GetTargetInfo(mainframeindex, 0).AimPointPosition
local missilepos = I:GetLuaControlledMissileInfo(a,b).Position
local missilespeed = I:GetLuaControlledMissileInfo(a,b).Velocity
local enemyspeed = I:GetTargetInfo(mainframeindex,0).Velocity
local mypos = I:GetConstructPosition()

if enemyspeed.magnitude > 170 then enemypos = I:GetTargetPositionInfo(mainframeindex, 0).Position
else enemypos = I:GetTargetInfo(0,0).AimPointPosition
end --if the enemy is really fast, aim at their COM rather than ai aimpoint

local relativepos = missilepos - enemypos
local relativespeed = missilespeed - enemyspeed
local time = math.min((relativepos.magnitude / relativespeed.magnitude), 5)
local predictedaimpoint = enemypos + enemyspeed * time - ((missilespeed / 5) * time)
local turnrateovertime = turnrate * time
local angle = math.abs(90 - math.acos((predictedaimpoint - missilepos).y / (predictedaimpoint - missilepos).magnitude) * (180 / math.pi))
local posmodifier = 0
local posmodifer2 = 0
local spreadterm = 0


if predictedaimpoint.y > 400 then posmodifier2 = -200
else posmodifier2 = 600
end--top-attack if enemy is low, bottom-attack if they are high

if posmodifier2 == -200 then angle = angle + 90 end
-- if we are in bottom attack mode, then measure angle differently

if (turnrateovertime - (turnrateovertime / 1.3) < angle) or (angle > 65) then posmodifier = 0
else posmodifier = posmodifier2
end--top attack until we can no longer manage it


if (mypos-enemypos).magnitude > relativepos.magnitude*2
or I:GetLuaControlledMissileInfo(a, b).TimeSinceLaunch > 10

then spreadterm = 0
else spreadterm = maxspread / (I:GetLuaTransceiverCount() * I:GetLuaControlledMissileCount(a)) end
--dividing the missiles evenly over the max spread area

if spreadterm == 0
then spread = 0
else spread = (spreadterm - (spreadterm * ( (a+1) * (b+1) ) - maxspread))
end --each subsequent missile is +1 spreadterm away from the last


vector = Vector3(predictedaimpoint.x + spread * math.sin(missileinfo.Azimuth), predictedaimpoint.y + posmodifier + spread / 10, predictedaimpoint.z + spread * math.cos(missileinfo.Azimuth))
--predicted aimpoint + spread + altitude modifier

I:SetLuaControlledMissileAimPoint(a, b, vector.x, vector.y, vector.z)

end
end
end
end
15 Comments
𝖍𝖆𝖓𝖘 (hans) 13 Jul @ 6:14am 
oh
nevermind then
Tachyon  [author] 13 Jul @ 6:12am 
That is what this Lua does. Just set the turn rate to really low (like 5-10) and it will do that

(This Lua bases trajectory on time until impact rather than distance though, but it should not make a difference)
𝖍𝖆𝖓𝖘 (hans) 13 Jul @ 6:10am 
it basically controld the trajectory of the missile according ro target distance etc
Tachyon  [author] 13 Jul @ 6:07am 
what does ballistic missile Lua do
𝖍𝖆𝖓𝖘 (hans) 13 Jul @ 6:06am 
would it be possible for ya to make a Ballistic missilu LUA?
the only one i found is only kinda working and quite hard to understnad
𝖍𝖆𝖓𝖘 (hans) 13 Jul @ 6:05am 
yeah i found that out quite quickly by just looking at the keybind list but thx anyways
Tachyon  [author] 13 Jul @ 5:57am 
lol

press shift + n on the launchpad and change the name to whatever you made the name in the lua (spaces and caps included)
𝖍𝖆𝖓𝖘 (hans) 13 Jul @ 4:30am 
nvm my brain is just smooth like a mirror
𝖍𝖆𝖓𝖘 (hans) 13 Jul @ 4:25am 
how do i change the name of launchpads tho
i cant for the love of god figurethat out
Tachyon  [author] 9 Jun @ 5:31am 
These are designed to be absolutely as computationally cheap as possible- the only FPS loss you get from it are the rendered missiles.