Unity 2D Enemy movement problems

Currently, all my script does is make them fly and follow the player (which is cool but not what I’m looking for for most of the enemies), I’m trying to have enemies actually walk on the ground like the player does, here’s the script I’m using
`using UnityEngine;
using System.Collections;

public class Enemy_movement : MonoBehaviour {

	public Transform target;
	public int moveSpeed;
	public int rotationSpeed;
	
	void Start() 
	{
		target = GameObject.Find("Michael").transform;
	}
	
	void Update() 
	{    
		if (target != null) 
		{
			Vector3 dir = target.position - transform.position;
			// Only needed if objects don't share 'z' value.
			dir.z = 0.0f;
			if (dir != Vector3.zero) 
				transform.rotation = Quaternion.Slerp ( transform.rotation, 
				                                       Quaternion.FromToRotation (Vector3.right, dir), 
				                                       rotationSpeed * Time.deltaTime);
			
			//Move Towards Target
			transform.position += (target.position - transform.position).normalized 
				* moveSpeed * Time.deltaTime;
		}
		GetComponent<Rigidbody2D>().velocity = Vector3.zero;
	}
}`

any suggestions on what to change (I’m still very new to game design and am using other posts to help me put my code together)

Since your code is not formatted, it makes it really hard to read… On your enemies’ Rigidbody2d you could just increase their gravity to make them fall on the ground.

Codfish1114

How is your setup? Do you have a xy-plane to move your characters on?
If so you could forget about the whole rotate thing and just invert the movement speed of your enemys if your players x changes in relation to them.

Example:

if (Player.tranfrom.position.x > enemy.transform.position.x) enemy.speed = 10;
else enemy.speed = -10;

Or something like that. If this doesnt help you please give more details on what you want to have here :smiley: