Game Development Reference
In-Depth Information
There's more...
By now, the character has a very intent stare at the camera. This is an improvement, but it
can be made more lifelike. Something that may not be so obvious is that we rarely look at
the same point all the time even if we look at the same object. We can emulate this behavi-
or by adding a random bit of flickering to the control:
private float flickerTime = 0f;
private float flickerAmount = 0.2f;
private Vector3f flickerDirection = new Vector3f();
By introducing these three fields, we have a base for what we want to do:
flickerTime += tpf * FastMath.nextRandomFloat();
if(flickerTime > 0.5f){
flickerTime = 0;
flickerDirection.set(FastMath.nextRandomFloat() *
flickerAmount, FastMath.nextRandomFloat() * flickerAmount,
0);
}
direction.addLocal(flickerDirection);
This piece of code goes in the middle of the controlUpdate method, right after calcu-
lating the direction. What we do is we increase flickerTime until it reaches 0.5f (note
that this is not in seconds since we apply a random number). Once this happens, we ran-
domize flickerDirection based on flickerAmount and reset flickerTime .
With each consecutive update, we will apply this to the calculated direction and slightly
offset the focus point.
Search WWH ::




Custom Search