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.