I am trying to continuously fire an object in the direction and angle the camera is facing. Currently it is firing but when I look up or down it doesn't fire in the proper angle.
Bellow is my code:
Code from Character.js
var projectile : Rigidbody;
/**
* exicutes continuously
* Creates an invisible bullets used to detect object hovers
*/
function Update(){
var clone : Rigidbody;
clone = Instantiate(projectile, transform.Find("Main Camera").position, transform.Find("Main Camera").rotation);
// Give the cloned object an initial velocity along the current
// object's Z axis
clone.velocity = transform.TransformDirection (Vector3.forward * 20);
}
Code from tracer.js:
var timeUp=false;
function Update () {
if(timeUp){
//Debug.Log("Detected Time Elapse");
// Destroy the projectile
Destroy (gameObject);
}
}
function Start(){
StopWatch(.2);
}
function StopWatch (time:float)
{
yield WaitForSeconds (time);
timeUp=true;
}
function OnCollisionEnter(collision : Collision) {
Debug.Log(collision);
if(collision.transform.name != "Character"){
Debug.Log("Detected Collision Test");
//Destroy the projectile
Destroy (gameObject);
}else{
Debug.Log("Detected Collision Test");
}
}