x


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!

more ▼

asked Jan 05 '12 at 04:58 PM

Krynn gravatar image

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

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
(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

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