Jump to content


Photo

enemy shooting at player


  • Please log in to reply
4 replies to this topic

#1 _241189

_241189

    GMC Member

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

Posted 03 March 2012 - 08:12 PM

i am creating a 2d plate former. I have an enemy that shoots bullets at the player. However i want the enemy to only shoot at the player when the enemy is facing the player and the player is on the left of the enemy.
  • 0

#2 RangerX

RangerX

    GMC Member

  • GMC Member
  • 998 posts
  • Version:GM8.1

Posted 03 March 2012 - 08:21 PM

Ok, it's just a question of finding the right condition for your shooting code to happen. Let's think this up together shall we?

If the player is on the left side of the ennemi, he's having a smaller X position.
So use that as condition (if playerX < EnnemyX)


And then you need to know if the ennemi is facing the player. Is your ennemi using a different sprite for going and right? Or maybe it's just the image_scale than changes when he changes direction?
- If it's a different sprite for going left than going right, use the sprite as the condition. if(sprite_index=SpriteForGoingLeft)
- If it's the image scale that decides where your ennemy is facing then use the xscale as your condition. if(image_xscale=-1)

So basically, in your ennemy and the corresponding event you need depending its behavior, you would have something along the lines of:

if(obj_player.x<obj_Ennemy.x)&&(image_xscale=-1)
then
{ shooting code }

Edited by RangerX, 03 March 2012 - 08:22 PM.

  • 1

#3 _241189

_241189

    GMC Member

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

Posted 03 March 2012 - 08:59 PM

Ok, it's just a question of finding the right condition for your shooting code to happen. Let's think this up together shall we?

If the player is on the left side of the ennemi, he's having a smaller X position.
So use that as condition (if playerX < EnnemyX)


And then you need to know if the ennemi is facing the player. Is your ennemi using a different sprite for going and right? Or maybe it's just the image_scale than changes when he changes direction?
- If it's a different sprite for going left than going right, use the sprite as the condition. if(sprite_index=SpriteForGoingLeft)
- If it's the image scale that decides where your ennemy is facing then use the xscale as your condition. if(image_xscale=-1)

So basically, in your ennemy and the corresponding event you need depending its behavior, you would have something along the lines of:

if(obj_player.x<obj_Ennemy.x)&&(image_xscale=-1)
then
{ shooting code }

how would i put this in the logic of the enemy object?
  • 0

#4 RangerX

RangerX

    GMC Member

  • GMC Member
  • 998 posts
  • Version:GM8.1

Posted 03 March 2012 - 09:04 PM

In drag and drop icons I am not sure. But that code i'd probably put it in a Step event. It actually depend what you're shooting code itself will be and how you want your ennemy to shoot.
  • 1

#5 _241189

_241189

    GMC Member

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

Posted 03 March 2012 - 10:09 PM

i think i figured it out thanks for your help
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users