Tranform.translate does not have constant speed

So in my 2d game their is a turret which aims in the direction of the player which works fine.It periodically creates bullets which also work fine.
Now the bullets use these following codes(i am only mentioning the ones responsible for movement)

public GameObject player;

public Vector3 target;

public Vector3 initial;

public float speed = 1;

void Start(){

player = GameObject.Find(“player”);

target = new Vector3(player.transform.position.x,player.transform.position.y,0f);

initial = new Vector3(transform.position.x, transform. position.y,0f);
}

Void Update(){

Vector3 dir =target-initial;

transform.position = transform.position+dirTime.deltaTimespeed;

}

And this actually works,using transform.Translate instead of transform.position works good too. But i noticed a little issue,when the player is near the turret the bullets spawned are moving at a much slower speed than the bullets spawned when the player is away from the turret.Meaning the speed of the bullets depends upon the initial distance between the mouth of the turret and the player.How do i fix this? I tried various methods for the code above.I want the bullets to continue moving in a direction even if they reached the position the player was initially at(the player may or maynot have moved from this position) and the code thankfully allows that.But again the speed is the issue.please help.

When you calculate your direction vector `Vector3 dir =target-initial;` you are getting a vector that contains both the direction to the target and the distance. You are then multiplying this vector by your speed and Time.deltaTime to get a delta position vector every frame. However since your dir vector has the distance between the source and destination in it, then your delta position calculation is also scaled by that distance. To get rid of the size of the direction vector, you want to normalize it, or set its magnitude to 1. Unity has a built in property that will help you with that →

``````Vector3 dir =(target-initial).normalized;

transform.position = transform.position+dir*Time.deltaTime*speed;
``````