Move towards mouse direction infinitely at constant speed

Ok so I solved the Input.mousePosition pointing the center of the camera with this:

pos = Input.mousePosition;
pos.z = 20;
pos = Camera.main.ScreenToWorldPoint(pos);

Solved moving infinitely to mouse position (direction) with this:

normalizeDirection = (pos - transform.position).normalized;
transform.Translate(normalizeDirection * speed * Time.deltaTime);

but after almost 5 hours of searching for solutions I cant make it so it moves at constant speed. If I move the mouse, the farther from the initial object position (in this case a projectile) the mouse is, the faster the object moves.
I don’t want this, I want a constant speed, no matter how close/far the mouse is from the initial object position.

I tried Lerp, MoveTowards as well, but in this case, I can’t even achieve the infinite movement, so I need a way to solve this with my current implementation

full code

public class projectile : MonoBehaviour {
    Vector3 pos;
	public int speed;
	private Vector3 normalizeDirection;

	// Use this for initialization
	void Start () {
        pos = Input.mousePosition;
	    pos.z = 20;
	    pos = Camera.main.ScreenToWorldPoint(pos);
	    normalizeDirection = (pos - transform.position).normalized;
	}
	
	// Update is called once per frame
	void Update () {

	}

	public void FixedUpdate(){
	    transform.Translate(normalizeDirection * speed * Time.deltaTime);
	}
}

Please help me, I’ll go to sleep, I’m so tired and frustrated right now.

Thanks.

Hmm is this from a first or top down perspective? I managed to get it working from the top down perspective by using this:

// Use this for initialization
void Start () {
	pos = Input.mousePosition;
	pos.z = -0.1f;
	pos = Camera.main.ScreenToWorldPoint(pos);
	transform.LookAt(pos); 
}

// Update is called once per frame
void Update () {
}

public void FixedUpdate(){
	transform.Translate(transform.forward * speed * Time.deltaTime);
}

}

public void FixedUpdate(){
transform.Translate(normalizeDirection * speed * Time.deltaTime);
}

You’re using Time.deltaTime inside FixedUpdate, you should be using Time.fixedDeltaTime. Otherwise you’re moving more in some frames than others, since deltaTime is different on each frame.

I was brought to this forum with my Unity 2D game and am posting my solution for those other poor souls.

            //Get the mouse
            Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            mousePos = new Vector3(mousePos.x, mousePos.y, 0);

            //Rotate the sprite to the mouse point
            Vector3 diff = mousePos - transform.position;
            diff.Normalize();
            float rot_z = Mathf.Atan2(diff.y, diff.x) * Mathf.Rad2Deg;
            transform.rotation = Quaternion.Euler(0f, 0f, rot_z - 90);

            //Move the sprite towards the mouse
            transform.position += transform.up * speed * Time.deltaTime;

Also if you want to move it away from the mouse do “transform.position -=” instead of “+=”