Homing Enemies issue (2D)

So i’m trying to make enemies in the form of projectiles that chase the player. The script I have does what I want it to do, the enemies DO follow the player, but they move in ways I don’t want them to. More specifically, the game is supposed to be 2D on the X-Y Plane yet to chase the player the projectiles often loop-de-loop into the z-axis. I don’t want that, I want them bound to the X-Y plane.

Here is the code (Java)

var target : Transform; 
var moveSpeed = 4;
var rotationSpeed = 1;
var myTransform : Transform;

function Awake()
{
myTransform = transform;
}

function Start()
{
target = GameObject.FindWithTag("Player").transform;
myTransform.rotation = Quaternion.LookRotation(target.position - myTransform.position);
}

function FixedUpdate()
{
var lookDir = target.position - myTransform.position;
//lookDir.z = 0;
myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(lookDir), rotationSpeed*Time.deltaTime);
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}

I know myTransform.forward sends the projectiles into the z-axis, but changing it to right or up causes the projectiles to behave incredibly oddly. The same thing happens when I try to implement the lookDir.z code you see commented out.

Also one last thing: Is there a way to change the movement of the projectile in such a way that the Physics2D material I have attached to it bounces off the rigidbody2D of the player?

So any help? What seems to be the problem?

Add the line

transfom.position = new Vector3(transform.x, transform.y, 0);

This will constrain your object to stay on the plane.

As an aside, why are you caching transform in myTransform?