Re: Request; Detection and velocities
I'd recommend casting a fan of MORays for this, using a for loop. Something like this, except this is untested and might not work:
Code:
function Create(self)
self.detecRange = degtorad(180);
self.rayCount = 30;
self.angleInc = self.detecRange/self.rayCount;
self.range = Vector(500,0)
self.target = nil;
self.velChanged = 0;
end
function Update(self)
local flightAngle = self.Vel.AbsRadAngle;
if self.target == nil then
for i=0, self.rayCount do
local rayVector = self.range:RadRotate((flightAngle-(self.detecRange/2))+self.angleInc*i);
local rayDurp = SceneMan:CastMORay(self.Pos, rayVector, self.RootID, -1, 0, false, 1);
if rayDurp ~= nil then
self.target = MovableMan:GetMOFromID(rayDurp);
break;
end
end
elseif self.velChanged == 0 then
self.velChanged = 1;
local angle = SceneMan:ShortestDistance(self.Pos, self.target.Pos, true).AbsRadAngle;
self.Vel = self.Vel:AbsRotateTo(angle);
end
end
In particular am i uncertain about AbsRadAngle, since the wiki says that it returns negative values when the angle is upwards, so to say. But hey, i tried, right? :U (also it's not perfect, the rays have large gaps between them)
Edit: Also note, this thing is set to ignore team -1, which may/may not be preferrable to change, depending on how much you love friendly fire.
Secondary edit: ALTERNATIVELY, determine a field of detection like this (self.Vel.AbsRadAngle +/- self.detecRange/2), and instead of using MORays which probably take a lot of CPU power, check the AbsRadAngle of the shortest distance between the bullet and the thing in question, and then check whether it's within the range or not, and whether the thing is close enough as well.