Melee Problem
by Mary Balmert · in Torque Game Engine · 10/29/2009 (12:48 am) · 6 replies
I'm trying to implement a simple melee resource that SOUNDED like it would work very simply and do exactly what I want. It's from an old post: http://www.garagegames.com/community/forums/viewthread/27228
In which, Manoel Neto wrote some code which I'm not sure works:
He said -
I can't get this code to work for the life of me! I have the key bound, I've added echos to make sure the function is getting called and everything, but I can't get any sort of reaction from a stationary bot. The impulse doesn't seem to be working at all.
All I want ot do is be able to press a button and send bots flying from melee range without doing the "fire a projectile" fix. Am I wrong about this resource? It seems like it picks a radius and attacks all within the arc "minDot".
In which, Manoel Neto wrote some code which I'm not sure works:
He said -
Quote:
Well, if it's that simple, you don't even need code changes to spank some bots, or other players.
Bind this function to a key:
function attack(%val)
{
$mvTriggerCount3 = %val;
}
Now define this function in your player class namespace. In the starter.fps mod, this would be Armor. Note that the function already exists in player.cs in the starter.fps mod.
function Armor::onTrigger(%this, %obj, %triggerNum, %val)
{
%attackRadius = 1.5;
%minDot = 0.65;
%damage = 1;
if (%triggerNum == 3 && %val) {
InitContainerRadiusSearch(%obj.getPosition(), %radius, $TypeMasks::PlayerObjectType);
while(( %targetObject = ContainerSearchNext() ) > 0 )
{
//Skip itself
if (%targetObject == %obj)
continue;
//Calculate the dot product
%direction = VectorSub(%targetObject.getWorldBoxCenter(), %obj.getPosition());
%direction = VectorNormalize(%direction);
%dot = VectorDot(%direction, %obj.getForwardVector());
//Skip object if it's angle is too great
if (%dot < %minDot)
continue;
//Apply damage & impulse
%targetObject.applyDamage(%damage);
%targetObject.applyImpulse(%targetObject.getPosition(), %direction);
}
}
}
I can't get this code to work for the life of me! I have the key bound, I've added echos to make sure the function is getting called and everything, but I can't get any sort of reaction from a stationary bot. The impulse doesn't seem to be working at all.
All I want ot do is be able to press a button and send bots flying from melee range without doing the "fire a projectile" fix. Am I wrong about this resource? It seems like it picks a radius and attacks all within the arc "minDot".
#2
10/29/2009 (1:39 am)
if its the resource from year 2002 its to old, search for melee server resource...
#3
In other news, I managed to make the impulse vector work relative to the player.
Now to do some animations, wait times, and combo attack coding!
10/29/2009 (2:49 am)
There was a lingering error in my log... Sorry about that.In other news, I managed to make the impulse vector work relative to the player.
Now to do some animations, wait times, and combo attack coding!
#4
10/29/2009 (2:54 am)
Fair enough ;P. Glad you got it working. This is a pretty darn simple solution, I would never have imagined it would take so little to achieve.
#5
10/29/2009 (3:03 am)
What kind of game are you making Mary?
#6
This is more of a test than a finished game idea.
10/29/2009 (4:20 am)
Currently, I'm working on a quick and dirty melee game where you beat up a bunch of stupid bots (they will just walk toward you and attack)This is more of a test than a finished game idea.
Torque 3D Owner Daniel Buckmaster