I’m trying to make a bomberman clone and I’m struggling with the enemy AI.What I want is for the ai to move in straight line but it keeps bounsing and hiting the walls a lot, not moving in straight line. This is what I have right now, it works but it still bounces while trying to snap to the right coordinates:
void FixedUpdate() {
if (!dead) {
directionTimer += Time.deltaTime;
if (directionTimer >= directionTime) {
directionTimer = 0f;
ChangeDirection();
}
if (left) {
Vector3 pos = new Vector3(Vector3.left.x, Mathf.Round(transform.position.y) - transform.position.y, 0f);
transform.Translate(pos * speed * Time.deltaTime);
} else if (right) {
Vector3 pos = new Vector3(Vector3.right.x, Mathf.Round(transform.position.y) - transform.position.y, 0f);
transform.Translate(pos * speed * Time.deltaTime);
} else if (up) {
Vector3 pos = new Vector3(Mathf.Round(transform.position.x) - transform.position.x, Vector3.up.y, 0f);
transform.Translate(pos * speed * Time.deltaTime);
} else if (down) {
Vector3 pos = new Vector3(Mathf.Round(transform.position.x) - transform.position.x, Vector3.down.y, 0f);
transform.Translate(pos * speed * Time.deltaTime);
}
} else {
timer += Time.deltaTime;
if (timer >= time) {
DestroyMyself();
}
if (playAnim) {
anim.SetTrigger ("Dead");
playAnim = false;
collider.isTrigger = true;
}
}
}
Any way to make it move only in straight lines like this?
You can try the game here: link text
Thanks!