Question by
simon4jelonek · May 05 at 01:15 PM ·
2dtransformtransform.lookat
tranform.LookAt(playerTarget) ; 2D Beat em up enemy script
Scripting the enemy 2D Beat em up: is there a possibility to rewrite the script, that it is working for an 2D Beat em up? Because of this script, our Enemy is always rotating into (0 , 90, 0) and (0, -90, 0), we tried many solutions from other posts but it didn't work. Appreciate your help!
void FollowTarget () {
if (!followPlayer)
{
return;
}
if(Vector3.Distance(transform.position, playerTarget.position) > attack_Distance)
{
transform.LookAt(playerTarget);
myBody.velocity = transform.forward * speed;
}
if(myBody.velocity.sqrMagnitude != 0)
{
enemyAnim.Walk(true);
else if(Vector3.Distance(transform.position, playerTarget.position)<= attack_Distance)
myBody.velocity = Vector3.zero;
enemyAnim.Walk(false);
followPlayer = false;
attackPlayer = true;
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613060209im_/https://answers.unity.com/themes/thub/images/avi.jpg)