We have a very basic enemy in our game that shoots a projectile. The projectile isn’t affected by gravity, it just goes straight forward. The enemy is supposed to shoot at the player, which is an aircraft (so that means it moves with an almost constant speed). The problem is that because the player is moving fast, the projectile can never hit it which makes the enemy pointless. I’ve been reading articles about prediction, but all of them have to deal with collision testing and I don’t really need it. I want to predict where the player is going to be several minutes from the shooting moment so the enemy will know where to shoot.
What is known:
S - The player’s speed
PS - The projectile’s speed
Dir - The player’s movement direction
Dist - the distance between the player and the enemy
The projectile should be fired at player.transform.position + player.transform.forward * X where X is the distance from the player that I’m trying to find. So far we got something but I’m not sure we’re even looking in the right direction:
var targetDistance : float = Vector3.Distance(transform.position, target.position);
var timeToHit : float = targetDistance/100;
var playerEstimation = PlayerControl.shipMove*timeToHit;
var prj : GameObject = Instantiate(projectile, transform.position+transform.forward*3, Quaternion.identity);
pointLook = target.position + target.forward * playerEstimation;