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.
Any help would be greatly appreciated.
Associate Steve Acaster
[YorkshireRifles.com]
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.