Ok, I actually took the time to read the topic well, and this is a good concept.
Though a idk how to get the position of the muzzle node, so I will just use the position of the player.
function getTimeFromDistance(%dist)
{
return %dist / 0.3 * %dist;
}
function getDistanceFrontObject(%obj)
{
if(!isObject(%obj))
return 0;
%scale = getWord(%obj.getScale(),2);
%starter = %obj.getEyePoint();
%vec = %player.getEyeVector();
%end = vectorAdd(%start,vectorScale(%vec,2 * %scale));
%col = firstWord(%ray);
if(isObject(%col))
return vectorDist(%obj.getPosition(),%col.getPosition()) TAB %col;
else
return 0;
}
function "WeaponImageGoesHere"::onFire(%this,%obj,%slot)
{
%diststr = getDistanceFrontObject(%obj);
%dist = getWord(%diststr,0);
%pos = vectorAdd(%obj.getEyePoint(),%dist);
if(%dist > 0)
{
%time = getTimeFromDistance(%dist);
if(%time > 0)
schedule(%time,'',doExplosion,"-projectilehere-",%pos);
}
}
function doExplosion(%projectile,%pos)
{
new Projectile()
{
datablock = %projectile;
initialPosition = %pos;
initialVelocity = "0 0 0";
sourceObject = 0;
sourceSlot = 0;
client = 0;
scale = "1 1 1";
}.explode();
}
It could work, but idk.
Read threw the script, and tell me what I need to do.
I think in a second I know a fix, but ill just post here for now for safe keeping or whatever.
That should work, replace weaponimagehere and -projectilehere- with the weapon image and the projectile that explodes.
Then it should do the rest itself.