How do I make a game object freeze in the y axis when hitting a collider?

#pragma strict
var Ggroup : GameObject;
var group: GameObject;
var moveSpeed : float = 0;
var speed : float = 6;

function Start () 
	Ggroup = GameObject.FindGameObjectsWithTag("Enemy1");
	for(var i=0;i<6;i++)
			for each (E in Ggroup)
					if (Vector3.Distance(E.transform.position,transform.position)<150)
  •  				break;		*
  •  			}*
  •  		}*
  •  }*


function Update ()

  • for (var x=0;x<group.Length;x++)*
  • {*
  •  if(Vector3.Distance(group[x].transform.position,transform.position)<3)*
  •  	{*
  •  		Debug.Log("avoid");*
  •  		var delta = group[x].transform.position - transform.position;*
  •  		delta.Normalize();*
  •  		delta =;*

_ transform.position = transform.position + (delta * moveSpeed);_

  •  	}*
  • }*

This is the script I gave to enemies that spawn so that they avoid each other (part of a flocking algorithm), the problem is that sometimes to avoid each other they jump in the y axis rather than moving away in the horizontal axes of the scene.
I think the best way to avoid this would be to freeze them in the y axis once they hit the collider of the terrain (they spawn higher up and I don’t want them to freeze in the y axis on spawn), is it possible for me to do it? What would I need to do?

If you wish to permanently freeze them in the Y-axis, click their rigidbody, click constraints, and tick whatever option/axis you want for freezing.