Game Development Community

Automatically follow another player

by Joey Skinner · in Technical Issues · 03/27/2007 (10:00 am) · 5 replies

I posted this in the AI forum but haven't gotten any response. I'm trying it here to see if there are any ideas.

I know it is not typical for a first person player to need AI movement. But I have the player mounted on a vehicle (a horse) which is following another player. So I want the vehicle to have some intelligence to follow the player. I have it working by putting code in the vehicle's getAIMove method to look at the player's position compared to the vehicle's position, and then setup the rotate and move to go there.

But when the game is played, the first person view is too jerky because the other player is constantly moving and the vehicle to which the first person player is mounted is constantly moving to follow it. Normal AI moves for non controlled players don't have to worry about smoothness when they follow another player because there is no camera involved. So I'm guessing it is not common to have to worry about smoothing things out.

Does anyone know of a way to smooth things? Or, does it seem like I've forgotten something or have done something wrong?

Thanks in advance.

#1
03/27/2007 (10:38 am)
The rotate is probably what's causing the jerkiness.
#2
03/27/2007 (11:26 am)
I would agree with that. Any ideas on how I can fix it?
#3
03/27/2007 (3:36 pm)
A Kalman filter.
#4
03/27/2007 (10:09 pm)
Hmm. I did some reading on a Kalman filter. Seems pretty complex. But thanks for the suggestion. I was hoping there was some sort of tracking code already available in Torque. It also seems like any move returned from getAIMove would do the proper prediction so it was not jerky on the client.
#5
03/28/2007 (6:01 am)
It is complicated at the documentation level to follow but devilishly straightforward to implement once the details are understood. That is especially true with TGE because everything you need is already in the engine: TGE is quaternion based, has a good library of Matrix algebra, etc.

The heart of the matrix calculations looks a little like this:

E = C*P*Ct+R
K = P*Ct*inv(E)
X += K*err;
P -= K*C*P;

Qdot = W * Q
Q += Qdot * dt

where P is the covariance, R is the estimated noise, etc., and Q is the new estimated orientation in quaternions.

This looks expensive computationally and it is, especially the inverse. But for most applications it doesn't have to be done at frame rate, just often enough to keep an object pointed smoothly in the presence of a noisy input. On the other hand one wouldn't want to be filtering all three axis for more than a couple of object's movement this way in a game. The code runs pretty fast though on most of this generation of PC's, needing less than a millisecond to execute the algebra. If you only implement one axis, like yaw for your example, it reduces to a simple subset of code and the inverse() disappears.

I'll try implementing the three axis version in the game and see how it goes. I already have it running in another robotic application using different libraries and can convert it. It would be an excellent resource to have around. I'm not sure what the client/server implications are yet, though.

Edit:
I'll post more about this on a separate thread in the private forum as it will involve discussing the engine code at a detail level.