Delay in setAimObject?
by Jacob Williams · in Torque Game Engine · 01/06/2009 (8:17 am) · 3 replies
I am having an interesting issue with setAimObject, and I will do my best to explain it here. I have a set of functions that allow me to use mouse control for most of my game. Because of setMoveDestination, I am using the AIPlayer class as opposed to the Player Class. Here is the function in question:
Now, the issue is that when I click on a player, it doesn't aim at the target and fire, but rather fires the weapon and then aims at the target. (Basically, the first click fires off into space while the second hits the target.) I have tried scheduling the fire command, but one, it doesn't work, and two, I want the player to be able to fire as fast as the user can click. Any ideas on the delay of setting the aim object?
Any help is appreciated!
function serverCmdSelectObject(%client, %mouseVec, %cameraPoint)
{
//Determine how far should the picking ray extend into the world?
%selectRange = 1000;
// scale mouseVec to the range the player is able to select with mouse
%mouseScaled = VectorScale(%mouseVec, %selectRange);
// cameraPoint = the world position of the camera
// rangeEnd = camera point + length of selectable range
%rangeEnd = VectorAdd(%cameraPoint, %mouseScaled);
%Player = ContainerRayCast (%cameraPoint, %rangeEnd, $TypeMasks::PlayerObjectType, %player);
if (%Player)
{
%targetObject = firstWord(%Player);
%client.player.aimAt(%targetObject);
%client.player.fire(true);
}
}Now, the issue is that when I click on a player, it doesn't aim at the target and fire, but rather fires the weapon and then aims at the target. (Basically, the first click fires off into space while the second hits the target.) I have tried scheduling the fire command, but one, it doesn't work, and two, I want the player to be able to fire as fast as the user can click. Any ideas on the delay of setting the aim object?
Any help is appreciated!
About the author
#2
01/06/2009 (11:55 am)
I'm pretty sure I know what your talking about, as my AI players had a similar problem. I used the following code to schedule my AI's shooting:. . . . %this.schedule(10, setImageTrigger, 0, true); . . . .You might use something like:
. . . . %client.player.schedule(10, fire, true); . . . .Now I understand what you mean about firing as fast as the user can click, but it's only a 100th of a second delay (and my not even require that much).
#3
01/07/2009 (8:45 am)
Or, if you really want to kill the problem, you could hack into the AI aiming code and just have it rotate immediately to the correct facing. Though I'd only do that if you never need a smooth rotation when aiming.
Torque Owner Daniel Buckmaster
T3D Steering Committee
My second thought would be to implement shooting logic inside the AIPlayer class itself. If it's been told to fire, it will wait until it has its target lined up first. I've done something similar for firing with a random delay, so if you tell a whole squad to fire with one script call, each shot has a random delay, making the characters seem far less artificial.