Hi, noob here again.
I have with enemy tile collision. They get stuck in walls everytime when they chase player, and often in idle state. Player collision works on the same code and it works perfect.
Game project is totally top-down shooter.
Heres code
EnemyTileCollision script
enemy step event code
Do you have any idea how to solve that problem?
I have with enemy tile collision. They get stuck in walls everytime when they chase player, and often in idle state. Player collision works on the same code and it works perfect.
Game project is totally top-down shooter.
Heres code
EnemyTileCollision script
GML:
function EnemyTileCollision(){
var _collision = false;
//horizontal
if(tilemap_get_at_pixel(collisionMap,x+hsp,y))
{
x -= x mod TILE_SIZE;
if(sign(hsp) == 1) x += TILE_SIZE - 1;
hsp = 0;
_collision = true;
}
//horizontal move commit
x += hsp;
//vertical
if(tilemap_get_at_pixel(collisionMap,x,y+vsp))
{
y -= y mod TILE_SIZE;
if(sign(vsp) == 1) y += TILE_SIZE - 1;
vsp = 0;
_collision = true;
}
//vertical move commit
y += vsp;
return _collision;
}
GML:
EnemyTileCollision();
image_angle = direction;
attackcol++;
#region enemy state
if(enstate == enemystate.idle)
{
image_angle = direction;
//zachowanie
counter += 1;
//zmiana state
if(counter >= room_speed * 3)
{
var change = choose(0,1);
switch(change)
{
case 0: enstate = enemystate.patrol;
case 1: counter = 0; break;
}
}
if(collision_circle(x,y, 128, o_Player, false, false))
{
enstate = enemystate.chase;
}
}else if(enstate == enemystate.patrol)
{
//zachowanie
counter +=1;
x+= hsp;
y += vsp;
//zmiana state
if(counter >= room_speed * 3)
{
var change = choose(0,1);
switch(change)
{
case 0: enstate = enemystate.idle;
case 1:
direction = irandom_range(0,359);
hsp = lengthdir_x(walksp, direction);
vsp = lengthdir_y(walksp, direction);
image_angle = direction;
counter = 0;
}
}
if(collision_circle(x,y,120 , o_Player, false, false))
{
enstate = enemystate.chase;
}
}else if( enstate == enemystate.chase)
{
//zachowanie
x+= hsp;
y += vsp;
image_angle = direction;
direction = point_direction(x,y,o_Player.x, o_Player.y)
hsp = lengthdir_x(chasespeed, direction);
vsp = lengthdir_y(chasespeed, direction);
image_angle = direction;
//zmiana stanu
if(!collision_circle(x,y, 128, o_Player, false, false))
{
enstate = enemystate.idle;
}
if(collision_circle(x,y, sprite_w_half, o_Player, false, false))
{
enstate = enemystate.attack;
}
}else if(enstate == enemystate.attack)
{
image_angle = direction;
direction = point_direction(x,y,o_Player.x, o_Player.y)
hsp = 0;
vsp = 0;
x+= hsp;
y += vsp;
if(!collision_circle(x,y,sprite_w_half, o_Player, false, false))
{
enstate = enemystate.chase;
}
if(!collision_circle(x,y, 128, o_Player, false, false))
{
enstate = enemystate.idle;
}
}
#endregion