Jump to content


Photo

AI help-Sight


  • Please log in to reply
5 replies to this topic

#1 monsterbrum

monsterbrum

    GMC Member

  • GMC Member
  • 44 posts

Posted 28 May 2012 - 06:16 PM

I have the "obj_enemy" wich has this code in its step event:
blocked = 0;
if collision_line(x,y,obj_guy.x,obj_guy.y,obj_wall,false,true)
{
blocked = 1;
}
now he has an 360° endless view pretty superhuman, but i want him a bit realistic.
idealy i would like to have an moving view (not an gamemaker view but what the enemy sees) with an limited range, much like from the "comandos", "desperados wanted death or alive" and "robin hood legend of sherwood" titles, if anyone had an code to do that that would be awsome.
Otherwise an 180° view with limited range witch is stationary with the guy, but ofcouse "walks" together with him.
With that said, if that would be possible, how could i make the view visable to the player?

using GM81 lite

Thanks alot in advance!

Edited by monsterbrum, 28 May 2012 - 06:39 PM.

  • 0

#2 dannyjenn

dannyjenn

    GMC Member

  • GMC Member
  • 2041 posts
  • Version:Mac

Posted 28 May 2012 - 06:35 PM

What you could do (although this is probably not at all the correct way of doing this) is make a sprite in the size and shape of the enemy's view (something like a triangle or wedge-shape) and then make it invisible and have it always appear in front of the enemy at the correct angle. Then use ordinary collision to check if the player is in his view.
And to make it so the player can see the view... just turn visibilty on (and set the alpha if you want).

Edited by dannyjenn, 28 May 2012 - 06:36 PM.

  • 0

#3 monsterbrum

monsterbrum

    GMC Member

  • GMC Member
  • 44 posts

Posted 28 May 2012 - 06:39 PM

What you could do (although this is probably not at all the correct way of doing this) is make a sprite in the size and shape of the enemy's view (something like a triangle or wedge-shape) and then make it invisible and have it always appear in front of the enemy at the correct angle. Then use ordinary collision to check if the player is in his view.
And to make it so the player can see the view... just turn visibilty on (and set the alpha if you want).


Yeah i allready thought of that, but if im gonna do that, i would look straight trough walls and stuff, so i will need or the thing i mentioned in the OP or something to block of the sprite..
  • 0

#4 dannyjenn

dannyjenn

    GMC Member

  • GMC Member
  • 2041 posts
  • Version:Mac

Posted 28 May 2012 - 06:56 PM


What you could do (although this is probably not at all the correct way of doing this) is make a sprite in the size and shape of the enemy's view (something like a triangle or wedge-shape) and then make it invisible and have it always appear in front of the enemy at the correct angle. Then use ordinary collision to check if the player is in his view.
And to make it so the player can see the view... just turn visibilty on (and set the alpha if you want).


Yeah i allready thought of that, but if im gonna do that, i would look straight trough walls and stuff, so i will need or the thing i mentioned in the OP or something to block of the sprite..

Oh, yeah... didn't think of that.
  • 0

#5 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 16788 posts
  • Version:GM:Studio

Posted 28 May 2012 - 07:04 PM

You can use the above method fine. It's clean and simple... As for the "see through walls", just do a check using collision_line. So, you have your enemy, you have your sight object. Your enmy when created creates the sight object like this...
//CREATE EVENT OF ENEMY
view=instance_create(x,y,OBJSIGHT); //create the view object
view.parent=id; //Link the view object to this instance

//END STEP EVENT
view.x=x; //Set the view object to the enemy position
view.y=y; 
view.image_angle=image_angle; //set the view to the same facing direction as the enemy

//DESTROY EVENT
with (view) instance_destroy();

Great! You now have your view object that follows your enemy and rotates with his direction too! But the player? Well, in the view object you would do this :

//COLLISION EVENT WITH PLAYER
if !collision_line(x, y, player.x, player.y, wall, false,true)
{
with (parent) spotted=true; //You can see the player! Do something!
}
else
{
 with (parent) spotted=false; //You cant see the player! Do nothing!
}


Now all you need to do is have a check in the enemy object that says "if spotted is true do something" and the "do something" is where you put the chase and shoot the player codes.
  • 1

#6 monsterbrum

monsterbrum

    GMC Member

  • GMC Member
  • 44 posts

Posted 28 May 2012 - 07:15 PM

Thanks Nocturne, i will try it out when i got eneugh time :P
by that, for the angel, i should buy gamemaker, wich i will have to think over..
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users