Re: Advanced Missile Launcher
You could replace this:
Code:
-- MORay is very accurate so you need to aim carefully to catch something
-- that's ok with large vessels but it can make harder to hit actors
-- Thats why we need to make three rays which make 10 degrees scanning ray
-- first we try direct hit, then +- 5 degrees rays
local angle = self.parent:GetAimAngle(true);
local wideangle = {};
local targetfound = false;
wideangle[1] = angle;
wideangle[2] = angle - 0.088; -- Angle in radians
wideangle[3] = angle + 0.088;
--Start scanning
for i = 1,3 do
-- When creating starting point for scanning ray we need it to be outside of firing actor
-- or CastMORay will detect firing actor and make it target. Targets closer than 90 pixels will
-- be ignored
local raystartvector = self.parent.Pos - Vector( -math.cos(wideangle[i]) * 90 , math.sin(wideangle[i]) * 90);
-- Offset for CastMORay , it don't need to know acrot position, only angles
-- 750 is the length of scanning ray
local rayendvector = Vector( math.cos(wideangle[i]) * 750 , - math.sin(wideangle[i]) * 750);
-- Cast ray and get id of MO hit by ray
local moid = SceneMan:CastMORay(raystartvector , rayendvector , 0 , 0 , false , 3);
-- SceneMan.g_NoMOID returned if we hit ground or hit nothing
if moid ~= SceneMan.g_NoMOID then
-- Get MO object from stored id
local mo = MovableMan:GetMOFromID(moid);
-- Always check if found object is still alive
if mo ~= nil then
-- Find wich actor found MO belong to
for actor in MovableMan.Actors do
if mo.RootID == actor.ID then
self.target = actor;
self.target:FlashWhite(50);
targetfound = true;
break;
end
end --for
end --if
end --if
if targetfound then
break;
end
end --for
With this:
Code:
local maxangledifference = 0.088
for actor in MovableMan.Actors do
local vectortoactor = actor.Pos - self.Pos
if math.abs(vectortoactor.AbsRadAngle - self.Vel.AbsRadAngle) < macangledifference and vectortoactor.Magnitude < 750 then
self.target = actor
maxangledifference = vectortoactor.AbsRadAngle
end
end
I used that in some version of the Swarmer in Lua guns, though I seem to have lost the script somewhere.
Edit: Forgot the distance check. Added it.