Game Development Community

Fireball help

by Minesh · in Torque Game Engine · 08/03/2009 (2:15 pm) · 3 replies

I am working on a Fireball that sets some floating flames..
that works but i can't get the thing to home i tried
function FireballImage::onFire(%this, %obj, %slot)
{
%projectile=%client.getransform;
}
i know its horriblywrong due to the fact it crashes :S
So i was wondering how to fix this

#1
08/03/2009 (2:34 pm)
Who or what is %client in that function? That little snippet has no working functionality at all.

Local variables, those that are preceded by a % sign are only relevant to the functions that they are used in and/or passed to. The reason that is probably crashing is because you are assigning a new local variable of %projectile to an unkown, %client, and then calling a method on this unknown entity, getTransform... and syntax was wrong for that also.

Trying to create a "homing" projectile in script would be really difficult to work correctly. You need to figure out your eye/muzzle vector of wherever you're shooting from, compare it to a woldspace location of what you're trying to shoot at, do some tricky math and extrapolate a new vector for the projectile to use in order to hit said target. But that would not be true homing behavior only targeting and then a straight shot, so you may as well just "shoot" your fireball after you aim it just like you would a weapon.

Once your projectile is created then you could schedule a repeating function that checked it's position as well as the target's position every 'x' of a second. Inside this repeating function you could then do the necessary comparison and checks to produce a new vector and if there is enough of a change then store the current projectile location, delete the current projectile, and then spawn a new projectile on the new vector heading. Repeat until you hit the target. Very hacky and also problematical. It could be done, but isn't anything that I've done recently so I don't have any code to show how to do so -- but those are the steps I would use.

Alternatively there is already a guided/homing projectile resource, but that requires access/license to the source code in order to make use of it.
#2
08/03/2009 (2:38 pm)
hmm so like first i could start of by making a part sees the nearest client then it targets that client and goes after it
#3
08/04/2009 (2:10 am)
%obj.playthread(2, armattack);
%initPos = %obj.getEyeTransform();
%muzzleVector = %obj.getMuzzleVector(%slot);
%objectVelocity = %obj.getVelocity();
%muzzleVelocity = VectorScale(%muzzleVector, 20);
%p = new Projectile()
{
dataBlock = fireballProjectile;
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,"homingprojectilehome",%p);
MissionCleanup.add(%p);
return %p;
}
function homingprojectilehome(%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
//echo("homing");
%pos=%projectile.getposition();
%targ=vectoradd(%projectile.target.getposition(),"0 0 1.5");
%diff=vectorsub(%targ,%pos);
%p = new Projectile()
{
dataBlock = fireballProjectile;
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,"homingprojectilehome",%p);
%projectile.delete();
return;
%projectile.initialVelocity=vectorscale(%diff,10/vectorlen(%diff));
schedule(200,0,"homingprojectilehome",%projectile);
%projectile.initialPosition=%projectile.getposition();
}
function FireballProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
cancel(%obj.event);
weaponDamage(%obj,%col,%this,%pos,Fireball);
radiusDamage(%obj,%pos,%this.damageRadius,%this.radiusDamage,Fireball,%this.areaImpulse);
}


function BurnFire(%client,%obj)
{
%obj.ChargeFire.delete();
%obj.Burned.delete();

}

BAM! well thats it thats mostly what i did