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 } } }
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\$