Game Development Community

Getting hurt by enemy ai

by Craig Lallathin · in Torque Game Engine Advanced · 11/05/2009 (4:35 pm) · 3 replies

How do I make it to where the player gets hurt by the enemy player when they run into each other?
Any help would be greatly appreciated.

#1
11/05/2009 (5:02 pm)
In AIplayer.cs you need an onCollision() function much like the one in player.cs. Change "theAIplayer" to whatever datablock your AI is using (probably demoplayer - it will say in your aiplayer.cs script)
function theAIplayer::onCollision(%this,%obj,%col)
{
   if (%obj.getState() $= "Dead")
      return;

//here's where the magic happens

//make sure it's a player we've collided with
   if (%col.getClassName() $= "Player")
	{
//the amount of damage we want to do
        %damage = 40;

//and then apply it to the object/player we have collided with
        %col.applydamage(%damage);

//and then give them an impulse to knock each other away
           %colpos = %col.getWorldBoxCenter();
           %objpos = %obj.getWorldBoxCenter();
           %imp = vectorSub(%objpos,%colpos);
           %imp = vectorScale(%imp,2000);
           %obj.applyImpulse(%col.getWorldBoxCenter(),%imp);
	}
}

So the key function here is applydamage(). If you select a player or AI in the editor you'll see there name or ID number, and you can use that to call a "dump" on them - (no sniggering at the back) - will list all of the stock functions available for that type of object.
eg - type into the console
1967.dump();
where 1967 is the object's ID.
#2
11/05/2009 (5:54 pm)
Thanks, now I have another problem, now I need it to also make me respond to the start point or where I die.
#3
11/05/2009 (5:57 pm)
Thanks, I finally got it to where he takes damage but when the player dies the player won't re-spawn.