Game Development Reference
In-Depth Information
audio.loop = true;
audio.Play(); // play the idle sound.
}
}
yield WaitForSeconds(idleTime);
while (true)
{
characterController.SimpleMove(Vector3.zero);
yield WaitForSeconds(0.2);
var offset = transform.position - target.position;
if (offset.magnitude < attackDistance)
return;
}
}
function RotateTowardsPosition (targetPos : Vector3, rotateSpeed : r
float) : float
{
var relative = transform.InverseTransformPoint(targetPos);
var angle = Mathf.Atan2 (relative.x, relative.z) * Mathf.Rad2Deg;
var maxRotation = rotateSpeed * Time.deltaTime;
var clampedAngle = Mathf.Clamp(angle, -maxRotation, maxRotation);
transform.Rotate(0, clampedAngle, 0);
return angle;
}
The next whole section tells the zombie to pursue the player and play the chase anima-
tion. The line animation.CrossFade(“Chase”); is of particular note, since it is a command
that creates a smooth transition between two animations—in this case, the idle animation
and the chase animation. This animation command is useful for a script that calls multiple
animations in a character or object. It also makes the zombie overshoot the player position
for an amount of time specified by extraRunTime . This is an element of the robot script from
the third-person platformer tutorial that was kept to make the zombie appear slow-witted.
function Attack ()
{
isAttacking = true;
if (attackSound)
{
if (audio.clip != attackSound)
{
audio.Stop(); // stop the idling audio so we can switch out the audio clip.
audio.clip = attackSound;
audio.loop = true; // change the clip, then play
audio.Play();
}
}
animation.CrossFade(“Chase”);
Search WWH ::




Custom Search