Game Development Reference
In-Depth Information
var angle : float;
angle = 180.0;
var time : float;
time = 0.0;
var direction : Vector3;
while (angle > 5 || time < attackTurnTime)
{
time += Time.deltaTime;
angle = Mathf.Abs(RotateTowardsPosition(target.position, rotateSpeed));
move = Mathf.Clamp01((90 - angle) / 90);
animation[“Chase”].weight = animation[“Chase”].speed = move;
direction = transform.TransformDirection(Vector3.forward * attackSpeed * r
move);
characterController.SimpleMove(direction);
yield;
}
var timer = 0.0;
var lostSight = false;
while (timer < extraRunTime)
{
angle = RotateTowardsPosition(target.position, attackRotateSpeed);
if (Mathf.Abs(angle) > 40)
lostSight = true;
if (lostSight)
timer += Time.deltaTime;
direction = transform.TransformDirection(Vector3.forward * attackSpeed);
characterController.SimpleMove(direction);
Now comes the section that tells the zombie to cause damage to the player if he or she
is within a punch radius that is placed by the script. If you decide to create your own spe-
cial animation for a claw swipe, apart from what you created in Chapter 8, this section is
where to play it with the script.
var pos = transform.TransformPoint(punchPosition);
if(Time.time > lastPunchTime + 0.3 && (pos - target.position).magnitude r
< punchRadius)
{
target.SendMessage(“ApplyDamage”, damage);
lastPunchTime = Time.time;
}
if (characterController.velocity.magnitude < attackSpeed * 0.3)
break;
yield;
}
isAttacking = false;
animation.CrossFade(“idle”);
}
Search WWH ::




Custom Search