Problem moving zombie to player

Hello everyone, let me explain my problem:

actually i would like the zombie sprite to move to the Player sprite but the zombie moves to a random place

The player moving script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MovingPlayerScript : MonoBehaviour
{
    
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if(Input.GetKey(KeyCode.Space))
        {
            transform.Translate(new Vector3(0, 1, 0) * 4f * Time.fixedDeltaTime);
        }
    }
}

The zombie script to move towards the player:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MovingToPlayer : MonoBehaviour
{
    public GameObject player;
    public float PlayerPosX;
    public float PlayerPosY;
    public float PlayerPosZ;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        PlayerPosX = player.transform.position.x;
        PlayerPosY = player.transform.position.y;
        transform.Translate(new Vector3(PlayerPosX, PlayerPosY) * 1f * Time.fixedDeltaTime);
   
    }
}

And the rotation player script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RotationPlayer : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        transform.rotation = Quaternion.LookRotation(Vector3.forward, mousePos - transform.position);
    }
}

Thank you for your help !

Hello,

The problem is that Translate function needs a direction, not a target position.

  var direction  = player.transform.position - transform.position;
  direction.z = 0;
  transform.Translate(direction * 1f * Time.deltaTime);

The other thing is that it would be easier if you work on Vector2, not Vector3, since you are working on a 2D game. Also use Time.deltaTime in Update instead of Time.fixedDeltaTime