I’m currently making the AI for my game, or the prototype AI, and I’m using the mechanim animator to animate it, so I’m making a boolean to check if the opponent is moving or not, so the animator will know what animation to play.
I’m having a problem with that, I’m checking if the opponent isn’t moving by using a “previous position” value and the print function to check if it’s working.
It isn’t, even when I get to print both positions, and it’s exactly the same, it still recognises it as moving.
Here’s the code:
void Update ()
{
if (myTransform.position == previousPosition)
{
moving = false;
print("IT ISNAE MOVIN!");
}
else
{
//moving = true;
print("IT'S ALIVE!" + transform.position.ToString() + previousPosition.ToString());
}
Debug.DrawLine(target.transform.position, transform.position, Color.red);
//Look at target
if (gameObject.tag == "Kruncanite")
{
myTransform.localRotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(new Vector3(target.position.x, 0, target.position.z) -
new Vector3 (myTransform.position.x, 0, myTransform.position.z)), rotationSpeed * Time.deltaTime);
}
else
{
myTransform.localRotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(target.position -
myTransform.position), rotationSpeed * Time.deltaTime);
}
//Move towards target
if(Vector3.Distance(transform.position,target.position) > followDistance)
{
myTransform.position += Vector3.forward * moveSpeed * Time.deltaTime;
}
if (gameObject.tag == "Kruncanite")
{
kruncaniteAnimation.SetBool("Moving", moving);
}
previousPosition = myTransform.position;
}
What am I doing wrong?