i have an enemy with a character controller attached to it and the following script attached to the enemy to have it walk / attack the player…
The problem im having is that when the model is in motion, the enemy starts to rotate off axis and it just looks so bad ,…here is a picture:
Here is the script im currently using:
//object to be followed
var detectObject: Transform;
//distance that will trigger following action
var distanceDetection: float;
var standing = false;
var attackSpeed = 4;
//var AttackEnemy : GameObject;
private var characterController : CharacterController;
characterController = GetComponent(CharacterController);
private var gravity = 100.0;
function Start()
{
//animation.wrapMode = WrapMode.Loop;
//animation.Play("idle");
}
function Update ()
{
if (detectObject)
{
var dist = Vector3.Distance(detectObject.position, transform.position);
//if distance is less than what is specified then do something
if(dist<distanceDetection)
{
//print("attack");
//animation.CrossFade("walk");
attack();
return;
}
else
{
//print("stop attack");
//animation.CrossFade("idle");
GetComponent(SmoothLookAt).enabled = false;
//GetComponent(ConstantForce).enabled = false;
}
}
}
function attack()
{
direction = transform.TransformDirection(Vector3.forward * attackSpeed);
characterController.SimpleMove(direction);
GetComponent(SmoothLookAt).enabled = true;
}
any ideas please?
