• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

npc field of view problem.

darijs1

Member
i didnt know where to post this, my appologies if this is the wrong section.
----------------------------------------------------------
Once upon a time.... (you can skip this part)
----------------------------------------------------------
im working on this small top down shooter game, and im trying to make my npcs approachable from the back so they dont see the player.
basically at the moment, the my obj_enemy is an npc that runs after and attacks me if im within the range ive set. so i wanted to make it a bit more advanced and create a FIELD OF VIEW for the npc, so that it attacks only if im inside the enemys FIELD OF VIEW.
i tried my best and failed.
-----------------------------------------------------------
DETAILS
----------------------------------------------------------
so far i have obj_enemy as the npc, obj_player as the player, and obj_eyesight as the intended FIELD OF VIEW.
im also very new to coding in game maker....just to put it out there.
---------------------------------------------------------
PROBLEM
---------------------------------------------------------
all i really need is to know how to stick obj_enemy and obj_eyesight together and make obj_eyesight be directed to where the obj_enemy is looking (obj_enemy is patrolling around the map, and rotates to his directions n sht).

then i shouldnt have much problems tweaking the collisions with obj_eyesight and the player.

--------------------------------------------------------

Any help, tips and ideas would be very much appreciated.
 

Bingdom

Googledom
Firstly, the enemy should create its own field of view instance and give it its own ID.

Which can easily be done like this:
Code:
inst = instance_create(x,y,obj_eyesight);
inst.creator = id;
Then all the obj_eyesight has to do is follow its creator's x,y and image_angle.
 

darijs1

Member
Firstly, the enemy should create its own field of view instance and give it its own ID.

Which can easily be done like this:
Code:
inst = instance_create(x,y,obj_eyesight);
inst.creator = id;
Then all the obj_eyesight has to do is follow its creator's x,y and image_angle.
thanks for the reply.
i used the code you gave me, and it spawned the obj_eyesight, which is a start, but the object just sits there, it dosent move with my npc. how do i do the rest? sorry, im really new to all this.
 

Bingdom

Googledom
You should put
Code:
x = creator.x;
y = creator.y;
image_angle = creator.image_angle;
In the step event of obj_eyesight.
Because the variable 'creator' carries the ID of the instance that created it. So what we are doing is getting the x, y and image_angle from 'creator' and putting it into our obj_eyesight
 
Last edited:

darijs1

Member
You should put
Code:
x = creator.x;
y = creator.y;
image_angle = creator.image_angle;
In the step event of obj_eyesight.
Because the variable 'creator' carries the ID of the object that creates it. So what we are doing is getting the x, y and image_angle from 'creator' and putting it into our obj_eyesight
why thank you very much, sir. that worked flawlessly.
 
Top