Enemy Chase?

C

Craiie

Guest
Hello, i'm trying to program a enemy chase state. I was trying to achieve that the enemy goes across the platform, turning on the edges (heights variable) but once in a radius of 10 it will follow the player off the edge and follow until out of range. Once out of range, it would go back to what it was doing before. It doesn't seem to be chasing the player.
Here's my code: (i'm making a platformer)

see below
 
Last edited by a moderator:
B

Blakkid489

Guest
Before I test your code myself. look at this topic real quick. It'll help get your question answered more from this community
 
C

Craiie

Guest
Before I test your code myself. look at this topic real quick. It'll help get your question answered more from this community
Thanks for that, i'm new. I usually post on the Gamemaker Reddit. Since that post, I managed to make the enemy follow the character, but now the attack isn't working. I'm assuming it's because of the follow code that it isn't stopping and attacking. Weirdly enough, when I hit the enemy, the character goes backwards like it got hit but no damage is taken and it doesn't die. (P.S it's only the chase Enemy. The other Enemies work..)

[solved]
 
Last edited by a moderator:

TheouAegis

Member
I see the enemy "attacking" the player, but I don't see the player attacking. I'm guessing your issue with the player attacking is you're referencing the enemy by its object index and not by its actual id.

Also, your Create Event says dmg=5 but your collision code says Zenta.hp-attackdmg, so I'm guessing attackdmg was defaulted to 0 in the parent.
 
C

Craiie

Guest
I see the enemy "attacking" the player, but I don't see the player attacking. I'm guessing your issue with the player attacking is you're referencing the enemy by its object index and not by its actual id.

Also, your Create Event says dmg=5 but your collision code says Zenta.hp-attackdmg, so I'm guessing attackdmg was defaulted to 0 in the parent.
Since this enemy is a child of obj_enemy, obj_enemy (that works) takes damage by a collision event in a obj_hitbox object. The code is this:
Code:
if (instance_exists(obj_enemy))
    hp = (obj_enemy.hp - obj_enemy.dmg)
How would I fix it to call for it's actual id? I have another enemy that doesn't fall off ledges that is a child of obj_enemy too and it works, attacking and all. It's just this one object.

In the obj_enemy, it also has simular collision code with the hitbox but the enemy gets pushed back.:
Code:
if (instance_exists(obj_hitbox))
    hp = (hp - dmg)
    vspd = -3;
    hspd = -25;
As for the attackdmg, I changed dmg to attackdmg, but the parent's attack damage when inherited is not 0: it's attackdmg = 10;
 
C

Craiie

Guest
Oh, I got it to work! I put an inheritance code in my step as well, it seemed to be looping.
 
Top