New enemy movement

// Side to Side
[SerializeField]
private Vector3 _sideOrigin;
[SerializeField]
private float _sideBoundary = 1.0f;
[SerializeField]
private bool _sideMoveLeft = true;
private float _sideOffset = 0f;
enum Movement { Down, Circular, SideToSide };
void Start()
{
//redacted
_sideOrigin = transform.position;
}
Vector3 movement = new Vector3(xValue, -1, 0);
if (_movement == Movement.SideToSide)
{
float distance = Vector3.Distance(transform.position, new Vector3(_sideOrigin.x, transform.position.y, transform.position.z));
Debug.Log(distance);
if ( distance > _sideBoundary)
{
_sideMoveLeft = !_sideMoveLeft;
_sideOffset = 2f;
}
if (_sideMoveLeft)
{
movement.x = -1 - _sideOffset;
_sideOffset = 0;
}
else
{
movement.x = 1 + _sideOffset;
_sideOffset = 0;
}
}
transform.Translate(movement * _speed * Time.deltaTime);
if (transform.position.y <= -6)
{
transform.position = new Vector3(Random.Range(-11.3f, 11.3f), 7.2f, 0);
_sideOrigin = transform.position;
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store