Author Topic: How to make projectile follow player?  (Read 4636 times)

Basically if I were to shoot toward a player, if it came close enough to the player, then it would go toward him.
Is this possible? If so, how?

Please no. People Aloshi has released like two of these, and they just lag the server to hell when more than two people use them at once. The engine isn't cut out for that sort of thing, it's really not. If you want to do this sort of stuff just start an e-petition to get Badspot to add a projectile-tracking resource.


Basically if I were to shoot toward a player, if it came close enough to the player, then it would go toward him.
Is this possible? If so, how?

Here this is my projectile home I used for my homing rocket launcher;
Code: [Select]
function HomingRocketImage::onFire(%this,%obj,%slot)
{
    %initPos = %obj.getEyeTransform();
%muzzleVector = %obj.getMuzzleVector(%slot);
%objectVelocity = %obj.getVelocity();
%muzzleVelocity = VectorScale(%muzzleVector, 20);
%p = new Projectile()
{
dataBlock        = HomingRocketProjectile;
initialVelocity  = %muzzleVelocity;
initialPosition  = %initPos;
sourceObject     = %obj;
sourceSlot       = %slot;
client           = %obj.client;
};
    %p.target=ContainerRayCast(vectoradd(%initPos,vectorscale(%muzzleVector,2)),vectoradd(%initPos,vectorscale(%muzzleVector,500)),$TypeMasks::PlayerObjectType);
    schedule(400,0,"projectilehome",%p);
    MissionCleanup.add(%p);
return %p;
}
function projectilehome(%projectile)
{
    if(!isobject(%projectile.target))return;//if the projectile is gone, it will return nothing, and nothing is NOT an object. this also checks the target, so it is actually faster
    if(isObject(%obj.client.minigame))
    commandtoclient(%client,'bottomPrint',"Homing!.",1);
    %pos=%projectile.getposition();
    %targ=vectoradd(%projectile.target.getposition(),"0 0 1.5");
    %diff=vectorsub(%targ,%pos);
    %p = new Projectile()
{
dataBlock        = HomingRocketProjectile;
initialVelocity  = vectorscale(%diff,10/vectorlen(%diff));
initialPosition  = %projectile.getposition();
sourceObject     = %projectile.sourceObject;
sourceSlot       = %projectile.sourceSlot;
client           = %projectile.client;
};
    %p.target=%projectile.target;
    %p.event=schedule(200,0,"projectilehome",%p);
    %projectile.delete();
    return;
    %projectile.initialVelocity=vectorscale(%diff,10/vectorlen(%diff));
    schedule(200,0,"projectilehome",%projectile);
    %projectile.initialPosition=%projectile.getposition();
    commandtoclient(%client,'bottomPrint',"No target found.",1);
}

function HomingRocketProjectile::damage(%this,%obj,%col,%fade,%pos,%normal)
{
   if(%this.directDamage <= 0)
      return;

   //direct damage doubles for crouching players
   %damageType = $DamageType::Direct;
   if(%this.DirectDamageType)
      %damageType = %this.DirectDamageType;

   if(%col.getType() & $TypeMasks::PlayerObjectType)
   {
      %col.damage(%obj, %pos, %this.directDamage, %damageType);
      %projectile.delete();
   }
   else
   {
      %col.damage(%obj, %pos, %this.directDamage, %damageType);
      %projectile.delete();
   }
}

Note that is does not delete the projectile on collision, also it homes when you aim dead on them, you can change anything you need/want to.

Please no. People Aloshi has released like two of these, and they just lag the server to hell when more than two people use them at once. The engine isn't cut out for that sort of thing, it's really not. If you want to do this sort of stuff just start an e-petition to get Badspot to add a projectile-tracking resource.

Bump for confusion.



Basically if I were to shoot toward a player, if it came close enough to the player, then it would go toward him.
Is this possible? If so, how?

Here this is my projectile home I used for my homing rocket launcher;
Code: [Select]

Note that is does not delete the projectile on collision, also it homes when you aim dead on them, you can change anything you need/want to.
[/quote]
I used this... but it doesn't seem to want to explode unless the player or thing its homing on, dies. How can I fix this?

Please no. People Aloshi has released like two of these, and they just lag the server to hell when more than two people use them at once. The engine isn't cut out for that sort of thing, it's really not. If you want to do this sort of stuff just start an e-petition to get Badspot to add a projectile-tracking resource.

Why should they no do it because you said not to?

Azerath; in the projectile's onCollision function simply delete the object.

Please no. People Aloshi has released like two of these, and they just lag the server to hell when more than two people use them at once. The engine isn't cut out for that sort of thing, it's really not. If you want to do this sort of stuff just start an e-petition to get Badspot to add a projectile-tracking resource.

Why should they no do it because you said not to?

Because as I stated, schedule-intense weapons cause servers to lag. Servers lagging makes playing on them kind of boring. Plus all the homing weapons i've seen so far are awful. Don't let your hatred of me cloud your common sense (if you have any?)

Please no. People Aloshi has released like two of these, and they just lag the server to hell when more than two people use them at once. The engine isn't cut out for that sort of thing, it's really not. If you want to do this sort of stuff just start an e-petition to get Badspot to add a projectile-tracking resource.

Why should they no do it because you said not to?

Because as I stated, schedule-intense weapons cause servers to lag. Servers lagging makes playing on them kind of boring. Plus all the homing weapons i've seen so far are awful. Don't let your hatred of me cloud your common sense (if you have any?)

You don't have to join those servers do you?

Azerath; in the projectile's onCollision function simply delete the object.
Can't find "onCollision". :/

Code: [Select]
function YourProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
     //delete object here
}

I can't remember which is the projectile, I think it's %obj.

I remember I was on a server with a guided missle mod... I fired it and crashed the server. Twice.

Azerath; in the projectile's onCollision function simply delete the object.
Can't find "onCollision". :/

What're you doing to find it? It won't show up with tab.

Just go projectileName::onCollision(%this,%obj,%col,%fade,%pos,%normal) in the script.