0
\$\begingroup\$

I'm trying to make an enemy collide with collision tiles in GML. I don't think there should be anything wrong with it; it compiles, but every time the enemy either immediately disappears, or just doesn't move at all! (It's somehow different for every one everytime I run it).

Create:

_enemyspeed = 3 * random_range(1, 1.25) _enemyhp = 5 

Step:

if _enemyfrozen <= 0 { direction = point_direction(x, y, oplayer.x, oplayer.y) _enemyinvincibility -= 1 if _enemyinvincibility < 0 { _enemyinvincibility = 0 } if place_meeting(x, y, obullet) { if _enemyinvincibility <= 0 { _enemyhp -= 1 _enemyinvincibility = 30 } } if _enemyhp <= 0 { instance_destroy() } } else { _enemyfrozen -= 1 if _enemyfrozen == 0 { sprite_index = sangryguyenemy _enemydirection = point_direction(x, y, oplayer.x, oplayer.y) _enemymovex = lengthdir_x(_enemyspeed, _enemydirection) _enemymovey = lengthdir_y(_enemyspeed, _enemydirection) if place_meeting(_enemymovex, y, ocolission) { x = _enemymovex } if place_meeting(x, _enemymovey, ocolission) { y = _enemymovey } } } 
\$\endgroup\$
5
  • \$\begingroup\$ It looks like we're missing the "if" that this "else" corresponds to? \$\endgroup\$ Commented Sep 1 at 19:40
  • \$\begingroup\$ oops yeah I copied it wrong its there \$\endgroup\$ Commented Sep 2 at 3:22
  • \$\begingroup\$ the first line should be if _enemyfrozen <= 0 { \$\endgroup\$ Commented Sep 2 at 3:24
  • \$\begingroup\$ I FIGURED IT OUT!!!!! var _enemymovex = lengthdir_x(_enemyspeed, point_direction(x, y, oplayer.x, oplayer.y)) var _enemymovey = lengthdir_y(_enemyspeed, point_direction(x, y, oplayer.x, oplayer.y)) move_and_collide(_enemymovex, _enemymovey, ocolission) \$\endgroup\$ Commented Sep 2 at 3:53
  • 5
    \$\begingroup\$ To correct code missing from your question, use the Edit link to update your post. To share a solution, post in the "Your Answer" box below. Explain what you changed and how that fixes the problem. \$\endgroup\$ Commented Sep 2 at 4:19

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.