TITLE CORRECTION: Make the projectile the player shoots travel in the direction the player is facing.
I have a 3rd person spaceship that I can fly on a 3D space and make it look at the mouse cursor, so it’s not necessarily facing the direction in which it is moving (like in Geometry Wars).
What I want now is for the ship to shoot in the direction it is facing. At the moment I only know how to use the Vector3.up or Vector3.forward, but these don’t take into account the direction the ship is facing…
So inside the projectile script where I tell it the direction of travel, how can I tell it to travel in the direction the ship was facing the moment it was spawned?
Here is my current projectile script (C#):
using UnityEngine;
using System.Collections;
public class PlayerProjectile : MonoBehaviour {
public float ProjectileSpeed;
//public GameObject ExplosionPrefab;
private Transform myTransform;
// Use this for initialization
void Start ()
{
myTransform = transform;
}
// Update is called once per frame
void Update ()
{
float amtToMove = ProjectileSpeed * Time.deltaTime;
myTransform.Translate(Vector3.forward * amtToMove);
}
}