- Home /
Field of view not working correctly, firing from behind
// 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!
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?
Your answer
Follow this Question
Related Questions
Control amount of bullets 2 Answers
My shooting system wont work, help 1 Answer
Shooting Cannons from a boat 1 Answer
Destroy() not working on collision 2 Answers
Issue with Timed Shooting in C# 1 Answer