I am making a 3D spaceship combat minigame.
I need to launch a projectile from my spaceship,
towards a position that is the targeted enemy position,
adding 30 or something to the local Z of that position (i.e, "shooting it ahead of the enemys forward path),
but I need to be grabbing that vector when the shot is instantiated,
so that it is traveling in a straight line (interpolating / following / lookat is not what i need).
Here is what I have, and it is working as coded, but the calculation that adds to the Z position ends up giving me a vector that is higher than the Z axis value in the world space, despite me using localposition.
what I need is, that vector to end up as higher than the ships Z axis value, so it is “In front of where the ship / target” was at the moment of that calculation.
void Start () {
player = GameObject.FindWithTag ("Player").GetComponent <Player> ();
Destroyshot ();
hasTarget = player.seesTarget;
if (hasTarget) {
target = player.locktarget;
targetahead = new Vector3 (target.localPosition.x, target.localPosition.y, target.localPosition.z + 30);
transform.LookAt (targetahead);
}
}
void Update () {
gameObject.transform.Translate (Vector3.forward * speed);
Debug.DrawLine (gameObject.transform.position, targetahead);
}