Looked for function CheckCollision, but could not find it.
I wanted to avoid any loops, or anything with any ForEach ... Visible/Colliding/Radius Actors checks or anything like that.
Decided it should be passed the class name you want to spawn (aC), a DrawScale Multiplier value (DSM), and the location vector (V).
It will return True if there is a collision, False if there is room for that actor to spawn with that size at that location.
So this morning I wrote up this bit:
Code: Select all
function bool CheckCollision(class<Actor> aC, float DSM, Vector V)
{
local Actor aa;
aa = Spawn(aC,,,V);
if (aa != None)
{
aa.Destroy();
aa.DrawScale = aa.DrawScale * DSM;
SetCollisionSize((aa.CollisionRadius * DSM), (aa.CollisionHeight * DSM));
V.z -= (aa.CollisionHeight * aa.DrawScale);
aa.SetLocation(V);
aa = Spawn(aC,,,V);
if (aa != None)
{
aa.Destroy();
return false;
}
}
return true;
}
Since I avoided writing an alternate method, got no way to tell which might be faster....
Just to complicate things a bit, one of the mutators I am using this in, need the check performed
after the actor has been spawned successfully at default size.
Want to adjust its size from 1/3 to 2x default size.
So this is how I call the above function. If no room to grow, it just sets the multiplier to 1.
*Note adjustment on DSM to check for 20% larger than actually needed. Figure that would increase
the odds the monster will be able to move, as well as spawn.
Code: Select all
...
F = FMax(0.3330, (FRand()*2.0000)); // grab a random value for drawscale multiplier
if (F > 1.0) // no need for this check for mini-monsters
{
V = monster.Location; // save our existing actors location
monster.SetLocation(vect(0,0,0)); // move existing actor off to vect(0,0,0) for a sec....
if (CheckCollision(monster.Class, (F + (F*0.2)), V)) { F = 1.0; } // check if room for growth. if not, set F back to 1.0
monster.SetLocation(V); // put the actor back, and continue with setup
}
... // rest of pawn setup here....