Simple avoidance of enemy

I want to do a very simple avoidance check on a single axis - for example a space invader base avoiding a falling bomb.

something like:

transform.position.x = Mathf.Lerp(transform.position.x,-enemy.position.x,speed);

This makes the transform aim for the inverse x position of the enemy. Of course, it’s not effective if both are close to zero on the X axis. Any ideas for a quick fix?

Very simple fix… check for the zero case and pick a direction :smile:

Use something like Mathf.Approximately

Nice idea - thanks :slight_smile: