Question by
hibeast1 · Dec 11, 2020 at 12:57 PM ·
velocitytransform.forwardtransform.lookat
using LookAt(), transform.forward but move only in X axis
///////////////////////// AI Script (Black Model) /////////////////////////////////////
IEnumerator Targeting()
{
while (isTargeting)
{
if(!isCrouch && !isAttack)
{
transform.LookAt(player);
transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, 0);
if(Vector3.Distance(player.position, transform.position) > attackDistance)
{
rb.velocity = transform.forward * moveSpeed + new Vector3(0, rb.velocity.y, 0);
anim.SetBool("Run", true);
}
attackTimer += 0.05f;
}
if(Vector3.Distance(player.position,transform.position) <= attackDistance && isGround && !isCrouch && !isAttack && !isFalling && attackTimer >= attackDelay)
{
attackTimer = 0;
StopMove();
StartAttack();
}
rb.velocity = new Vector3(rb.velocity.x, Mathf.Clamp(rb.velocity.y, -25, 25));
if (rb.velocity.y < -3f)
{
isGround = false;
anim.SetBool("IsFalling", true);
isFalling = true;
}
yield return new WaitForSeconds(0.05f);
}
rb.velocity = new Vector3(0, rb.velocity.y, 0);
anim.SetBool("Run", false);
}
/////////////////// Player Script (White Model) ////////////////////////////
if(Vector3.Distance(Vector3.zero,dir) > 0.5f)
{
transform.LookAt(transform.position + dir);
rb.velocity = transform.forward * moveSpeed + new Vector3(0, rb.velocity.y, 0);
anim.SetBool("Run",true);
}
else if(anim.GetBool("Run"))
{
rb.velocity = new Vector3(0, rb.velocity.y, 0);
anim.SetBool("Run", false);
}
i used the same model, animation(run), function on both models but AI doesnt work well ai lookat player does work and goto player does work( only in X axis) so i dont know what's the problem
play video https://youtu.be/bZqUhKr-wiw
Comment