Hi guys I’d be really thankful if you helped me out because I really can’t find the problem (written in JS)
As the title says the problem is that I’ve gotten an unexpected char.
var Distance;
var Target : Transform;
var lookAtDistance = 30.0;
var chaseRange = 20.0;
var attackRange = 20.0;
var moveSpeed = 4.0;
var Damping = 6.0;
var attackRepeatTime = 1;
var theDammage = 40;
private var attackTime : float;
var controller : CharacterController;
var gravity : float = 20.0;
private var moveDirection : Vector3 = Vector3.zero;
function Start () {
attackTime = Time.time;
}
function Update () {
Distance.Vector3.Distance(Target.position,transform.position);
if(Distance <= lookAtDistance)
{
LookAtPlayer();
}
if(Distance <= attackRange)
{
AttackPlayer();
}
else if(Distance <= chaseRange)
{
ChasePlayer();
}
}
function LookAtPLayer ()
{
var rotation = Quaternion.LookRotation(Target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * Damping);
}
function ChasePlayer()
{
moveDirection = transform.forward;
moveDirection *= moveSpeed;
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
function AttackPlayer()
{
if (Time.time > attackTime)
{
Target.SendMessage("ApplyDammage", theDammage);
attackTime = Time.time * attackRepeatTime;
}
}
function ApplyDammage()
{
chaseRange += 30;
moveSpeed += 2;
lookAtDistance += 40;
}