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

I'm telling you, I used the finder, I manually looked for it, but I can't find anything.

I gave you the onCollision function. What do you mean you can't find it when it's posted on the previous page... twice?

I'm telling you, I used the finder, I manually looked for it, but I can't find anything.
Finder? I've never heard of that. Explain.

I gave you the onCollision function. What do you mean you can't find it when it's posted on the previous page... twice?
Failed.

Code: [Select]
function YourProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
     %obj.projectile.delete();
}

I think that may work.. IDk


Your right Ephiatles. It failed. And yes, I know it will be laggy and such, but I don't plan to release this. So chill out.

Code: [Select]
function YourProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
     %obj.projectile.delete();
}

I think that may work.. IDk

You're trying to delete the projectile's projectile.

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.

I'm willing to bet $100 that you did not write that yourself without copying off someone else. You can't even delete a projectile and here you are apparently messing about with vectors. I'm calling your bluff.

Why would you use this:

Code: [Select]
if(%col.getType() & $TypeMasks::PlayerObjectType)
Just use this:

Code: [Select]
if(%col.getClassName() $= "Player")

Why would he use either?

The code inside the if and else statements is the same.

Yes I know.  That's why Ephi said it's clear that not only did he not write the code, but he certainly doesn't understand it.  Understanding is key, idiots.

I still having trouble getting the projectile to explode. At first it hits him, but then it tails back an inch and repeats. Hoa2FixPlz? D:

I never said I wrote the code... I said the code I used in my Homing Rocket Launcher. The creator of the code was Qwertyuiopas, so if you have issues with the code then flame him not me.

Here this is my projectile home I used for my homing rocket launcher;

Admittedly, what you said is a bit misleading.