Hey Guys! I have a problem.
i animated a character, and made a simple AI Script, that the enemy first stares at me, and than (when i am near him) he runs at me. The Problem is: he walks sideways. I looked for answers from others who have the same Problem as me, but it didn’t helped. I tried to rotate the character in Cinema4D to look in front of the camera, but this doesn’t seem to affect the object. Transforming the object in the Inspector doesn’t help too. He always runs and looks at the wrong direction. Here’s the code i used:
var speed = 5.0f;
var focusDist : float = 10.0f;
var player : Transform;
private var enemyToPlayer : Vector3;
function Update()
{
zombiToPlayer = player.transform.position - transform.position;
var dist = zombiToPlayer.magnitude;
if( dist <= focusDist )
RunTowardPlayer();
else
Idle();
}
function RunTowardPlayer()
{
transform.rotation = Quaternion.LookRotation(enemyToPlayer);
gameObject.GetComponent( CharacterController ).Move( enemyToPlayer.normalized * speed * Time.deltaTime );
animation.CrossFade( "WFront", 0.3 );
}
function Idle()
{
animation.CrossFade( "Idle", 0.3 );
}
Please help me!