I’d like to fire in front of my enemy, but I can’t seem to figure out how I can manage to do that.
Here is my method:
private void FireInFrontOf(Transform target)
{
// Set height to fire from
Vector3 position = HeadTransform.transform.position + new Vector3(0, FireHeight, 0);
// Instantiate Projectile
GameObject projectileGO = (GameObject)Instantiate(ProjectilePrefab, position, HeadTransform.transform.rotation);
// Retrieve Projectile
Projectile p = GetProjectile(projectileGO);
if (p == null) return;
// Set Projectile attributes
p.Target = target;
p.Damage = Damage;
p.Radius = Radius;
}
I already found this:
target.forward*Time.deltaTime*DistanceUpFront;
But if I apply that to the targets position parameter before setting the projectile properties, the target moves over my screen.
Can anyone help me with this problem? Thank you!
In the attached files is a quick sketch for clarification of what I want to achieve.
