Predict where object will be

I am creating a top down turret defense game, and in those types of games when the turret shoots it always hits. What I am trying to do is calculate where an object will be based on the objects speed and the bullet speed so I can then rotate my turret to shoot at the correct location. If I point the turret directly at the object it will miss if the object is too far away.

My bullets/targets don’t use AdForce/Velocity, I am using transform.Translate() and transform.Rotate() to move everything, and all of the formulas I found are using velocity as part of their calculations.

I found the following on reddit and tried my best to convert it to C#, but it doesn’t work for me.

float aimAngle(Transform go, float bulletSpeed){
	float speed = go.FindChild("Logic").GetComponent<Character>().speed;
	float v = go.rotation.z * speed;
	float rCrossV = go.position.x * v - go.position.y * v;
	float magR = Mathf.Sqrt(go.position.x * go.position.x + go.position.y * go.position.y);
	float angleAdjust = Mathf.Asin(rCrossV / (bulletSpeed * magR));
	
	return angleAdjust + Mathf.Atan2(go.position.y, go.position.x);
}

Well, not directly answering your question, but here’s how i’d approach this problem : (as I mentioned in a comment)

Have your bullet be a class. Which has a target that can be set. - most probably an enemy.

Now, instead of predicting where the target will be in X time, just go towards it. continuously. adjusting rotation every frame

When you create the bullet, give it a target, and in its update code, have something like :

void Update()
	{
		transform.LookAt(target.transform);
		transform.Translate (transform.forward * speed);
	}

Just make sure your enemies never go faster than your bullets !

I would say that a proper tower defense game doesn’t allow this.
Either make you turrets shoot faster or make the bullet/projectile ALWAYS moving towards the first enemy in line.(Homing)

Also, consider using velocitys to move things around. It doesn’t make sense to “move” an object by changing the position manually. Let velocitys do that.

This is only true if you are using the FixedUpdate() instead of the Update(). Change to velocity if you want Update()
But to answer your question.
You know how fast the enemies are moving(units/second).
You also know the speed of the bullet to the target.

float a = (Length between tower and enemy) / bullet_speed. (prediction of how long it takes for the bullet to get to the enemy).

float b = enemy_speed * time (this is the distance the enemy walks from when the bullet are fired and when the bullet reaches the last enemy destination).

Solve C! Pythagoras theorem.

a^2 + b^2 = c^2

EDIT: This is only calculated when the enemy walks in a straight line after the bullet has been fired. So if your enemy does make a turn after the bullet has been fired, this does not work.