// field of view for NPC in degrees
var coneAngle : float = 20.0;
var enemy : GameObject;
var projectile : Rigidbody;
function Update() {
var clone : Rigidbody;
// Calculate the angle from the direction of the NPC to the player
var enemyDirection : Vector3 = enemy.transform.position - transform.position;
// if the angle is less than 20 degrees the NPC does something
if (Vector3.Angle(transform.forward, enemyDirection) < coneAngle) {
Debug.Log("see me!!!");
Debug.DrawRay (transform.position, enemyDirection * 10, Color.red);
// turn to player when it is in the NPC field of view
transform.LookAt(enemy.transform);
clone = Instantiate(projectile, transform.position, transform.rotation);
// Give the cloned object an initial velocity along the current
// object's Z axis
clone.velocity = transform.TransformDirection (Vector3.forward * 25);
}
}
// else
// {
// Debug.Log("noop");
// }
//}
I've tried everything I could think of doing such as using an empty game object, changing the transform.forward and enemyDirection around, etc.. o-o
Any ideas?
The model that has this on fires from it's backside, not the way it should be considered to be facing, it's very weird.
Thanks for any help!
asked
Jan 05 '12 at 04:58 PM
Krynn
21
●
5
●
7
●
12
Invert the direction of the local y-axis of the model/object that you are firing, its forward direction is the other way round maybe
What do you mean, "firing from behind"? Is it shooting to the opposite direction? Or the direction is ok, but the projectile is flipped backwards? Does the character correctly turn to the target direction? Or does it face the opposite side but fire in the correct direction?