# Field of view not working correctly, firing from behind

 0 ``````// 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-oAny 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! more ▼ asked Jan 05 '12 at 04:58 PM Krynn 21 ● 5 ● 7 ● 12 Bunny83 46.9k ● 12 ● 50 ● 210 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 Jan 07 '12 at 06:58 PM vatsalAtFEI 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? Jan 07 '12 at 10:59 PM aldonaletto add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

Be the first one to answer this question

By Email:

Topics:

x1726
x286
x59
x26

asked: Jan 05 '12 at 04:58 PM

Seen: 480 times

Last Updated: Jan 07 '12 at 10:59 PM