Blockland Forums > Modification Help

What would be the function that sets a delay of a raycast judging by distance?

Pages: (1/7) > >>

SWAT One:

          So my question, as posted as the topic title, is how I would get a raycast/hitscan bullet to delay it's explosion judging by the distance of the target.

As the projectile speed limit is 200, then the fastest that a bullet can travel 2000 brick studs is 10 seconds.

My question is if, supposing the Raycast scanning distance is unlimited, then can a function be written that detects distance, and gets the square root of it and multiplies it by a number less than it, approaching 0, that number sets the delay.  So say if something is 2000 studs away and the raycast detects the distance, it will fire with the function and divides by 3/10ths of the total distance (2000) and then sets the total value as the delay of the ray casting hit.
Fixed, see figure below.

It is figured as follows:

Where:
T is the time of the delay.
d is the distance between the muzzlePoint node and the target.  (Measured in brick studs, in this case 2000 brick studs)




You could say that this is cheating the speed limit, but with the recent controversies over raycast/non-raycast snipers, I've decided to post this as a solution of trying to make weapons that are velocity-accurate.  A working function of this objective would help weapon makers like myself make weapons of higher quality.  As it does not disobey the projectile speed limit, it should not lag when fired and to my knowledge isn't impossible.

So tell me what you all think?  Is this possible?  Have any ideas on how this would be written?

SWAT One:

~ Reserved ~

Brian Smithers:

function weaponFire::onFire(%this,%obj,%slot)
{
     //raycaststuf
     %raycast = raycastgetstuf();
     %time = timestuff(%raycast);
     schedule(%time,'',explodeStuff);
}
dingdingding
easy.

SWAT One:

Was asking how the equation would be put into the function too.

I need a complete function.  This is rather a new concept to just be blown off.

Brian Smithers:

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.


--- Code: ---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();
}

--- End code ---
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.

Pages: (1/7) > >>

Go to full version