If i make a basic square, stretch it out to match a realistic FOV. Then set it to, is trigger, and say this, would it work as a field of view, shooting the projectile on sight of the player?
function Update() {
function OnTriggerStay (other : Collider) {
if (gameObject.tag = “Player”){
var clone : Missile;
clone = Instantiate(projectile, transform.position, transform.rotation);
animation.Play(“alert”, PlayMode.StopAll); //rigidbody.AddForce(Vector3.forward * speed);
//another question about this, how do I call on a different rigidbody object to shoot forward instead of the box?
i dont understand, how exactly do I reference the instantiate ridgidbody for a different object in the scene, and I thought I took out the update function.
What if an enemy is inside the FOV but behind a wall?
It seems easier to compare the players forward vector against a vector pointing to the enemy player and use a something like Vector3.Angle(transform.forward, enemy.transform.position - transform.position).
If (angle > FOV / 2) then fire a ray at the enemy player position/direction. If it hits then the enemy is seen otherwise its invisible.
Like I say. Get a trigger working first. Understand how it works. And you can go from there. There is always a pattern. That is how I approached learning how to code.
If player is in trigger, do raycast? Simple right?
Alternatively we can scale the trigger based on a raycast shot from npc but that’s a bit more advanced.