Game Development Community

How to hit a certain target with a projectile?

by Wolfgang Kurz · in Torque Game Engine · 05/04/2007 (9:30 am) · 1 replies

Hello everyone,

I have a tank in a top down view and when i click on the screen the turret turns and firest a projectile

all great so far:-)

but i cant get the projectile to hit the point i clicked on :-)

Is there a way to set a traget for a projectile instead of a vector and its velocity?

this is my fire function which takes the object(tank) and the targetposition as parameters:
function TankShape::onTargetReached(%tank, %tar){
   // Create a big smoke emitter at the end of the gun when you fire
   %smoke = new ParticleEmitterNode() {
      dataBlock        = TankSmokeEmitterNodeData;
      emitter          = TankFireSmokeEmitter;      
   };
   %MuzzlePosition = %tank.getMuzzleTransform();
   %x = getWord(%MuzzlePosition,0);
   %y = getWord(%MuzzlePosition,1);
   %z = getWord(%MuzzlePosition,2);
   %z = %z+5;
   
   %smoke.setTransform(%x@" "@%y@" "@%z@" 0 0 0 0");     
   echo(%tar); 
   %muzzleVector   = %MuzzlePosition;
	%objectVelocity = %tank.getVelocity();

	%muzzleVelocity = VectorAdd( VectorScale(%muzzleVector, RocketProjectile.muzzleVelocity),
	                             VectorScale(%objectVelocity, RocketProjectile.velInheritFactor) ); 
   
   // Create a new rocket projectile object...
	%p = new (Projectile)()
	{
		dataBlock       = RocketProjectile;
		initialVelocity = %muzzleVelocity;
		initialPosition = %tank.getMuzzlePoint("Mount0");
		sourceObject    = %tank;
		sourceSlot      = "Mount0";
		client          = %tank.client;
	};

	MissionCleanup.add( %p );

}

would be awsome if anyone had an idea on how something like this could be done

thx a lot in advance for any hints:-)