Jump to content


Photo

Enemy Ai Shooting In Direction Of The Player


  • Please log in to reply
11 replies to this topic

#1 DivineMercyGames

DivineMercyGames

    GMC Member

  • New Member
  • 45 posts

Posted 10 January 2009 - 03:03 AM

Hi guys im making a TDS (top down shooter) and i was wondering if its possible to have the sprite of th enemy AI face you and then shoot?, I have got the player sorted but cant figure out how to do the enemies.
any help? (by the way the enemies are humans.)

Thanks in advance.

  • 0

#2 Obj_Control

Obj_Control

    GM Mentor

  • New Member
  • 2561 posts

Posted 10 January 2009 - 03:42 AM

I'm pretty sure there are many examples in the "tutorials and examples" section. Don't make the text big. We can all read.
  • 0

#3 DivineMercyGames

DivineMercyGames

    GMC Member

  • New Member
  • 45 posts

Posted 10 January 2009 - 03:51 AM

I'm pretty sure there are many examples in the "tutorials and examples" section. Don't make the text big. We can all read.


Yeah ok, ill check there then thanks.
some of us have eyesight problems :lol:
  • 0

#4 Snotrocket

Snotrocket

    GMC Member

  • New Member
  • 121 posts

Posted 10 January 2009 - 04:05 AM

yea seriously dont complain over some large text. does it hurt your eyes?
okay so i dont know what the game is like so i might not be helping you right for the sprite part. but for the shooting do this

in enemies shooting event, whatever you want that to be.... like if distance_to_object(hero) < 100 in the step event
instance_create(x+0, y+0, badenergy)

then for the bullet creation event put move_towards_point(hero.x, hero.y, 3)

3 is the speed it will move and since its in the creation event, it will only move towards him in that initial push.

for sprites you can rotate them with pro or get them to look straight left/right/up/down
id put something like

if hero.x > enemy.x and hero.y < enemy.y
{sprite index=toprightsprite}

and so on.
and just use distance_to_object to check whether the X or Y distance is greater... im not sure how to do that though
  • 0

#5 DivineMercyGames

DivineMercyGames

    GMC Member

  • New Member
  • 45 posts

Posted 10 January 2009 - 05:04 AM

thanks that great!
  • 1

#6 rowboat-synclaire

rowboat-synclaire

    Gungine Creator

  • New Member
  • 481 posts

Posted 10 January 2009 - 05:35 AM

create
alarmed = false


step
if distance_to_object (player) < 100
{alarmed = true}
if alarmed = true
{image_angle = point_direction(x,y,player.x,player.y)
instance_create(obj_bullet,x,y)}

thats some basic Enemy AI for yah. snot rocket did a good job of explaining it.
you don't have to do it with alarmed, but it allows you to add more commands and actions if you do it like that (eg, patrol, warned, etc)
  • 0

#7 DivineMercyGames

DivineMercyGames

    GMC Member

  • New Member
  • 45 posts

Posted 11 January 2009 - 12:29 AM

create
alarmed = false


step
if distance_to_object (player) < 100
{alarmed = true}
if alarmed = true
{image_angle = point_direction(x,y,player.x,player.y)
instance_create(obj_bullet,x,y)}

thats some basic Enemy AI for yah. snot rocket did a good job of explaining it.
you don't have to do it with alarmed, but it allows you to add more commands and actions if you do it like that (eg, patrol, warned, etc)


Hey i only have gmaker 6 :lol: . so i cant do image_angle.
is there any other method?
Thanks.
  • 0

#8 Potado

Potado

    GMC Member

  • New Member
  • 401 posts

Posted 11 January 2009 - 12:47 AM

Many many things are possible on gamemaker. This is definitly. Increase the direction. When your facing the player (point_direction) shoot
  • 0

#9 bobthecow

bobthecow

    GMC Member

  • GMC Member
  • 291 posts

Posted 11 January 2009 - 02:17 AM

try

BULLET CREATION EVENT

if instance_exists(player)
{
direction=point_direction(x,y,player.x,player.y);
speed=8;
}


There you go. This helped me.
  • 0

#10 BattleRifle BR55

BattleRifle BR55

    Moo

  • GMC Member
  • 8986 posts
  • Version:GM:Studio

Posted 11 January 2009 - 05:10 AM

some of us have eyesight problems :lol:

Those who have eyesight problems havemost likely increased the font size of their browers already.

And taken straight from the General GMC Rules

Do not post in all CAPS or use excessive color, bold or large text.


  • 0

#11 DivineMercyGames

DivineMercyGames

    GMC Member

  • New Member
  • 45 posts

Posted 11 January 2009 - 05:16 AM

Doesnt that just direct the bullet towards the player though? I need to make the enemy sprite face the player when shooting.
thanks.
  • 0

#12 BattleRifle BR55

BattleRifle BR55

    Moo

  • GMC Member
  • 8986 posts
  • Version:GM:Studio

Posted 11 January 2009 - 05:20 AM

Set the image angle of the enemy to the direction.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users