C
Chungsie
Guest
I have been following HeartBeast's rpg tutorial, and have been slightly modifying it with good results. For example I was able to add a run state, and the shown dash state, and was able to change animation speeds in states.
But now I am trying to make a ram enemy that moves up and down to line up 10% of y with player and then charge towards the player on the x axis.
my movement code for the ram is the following
I have tried changing the x and y variables to physics positions, but it gives me the same results.
the game looks like this, you walk on a platform in a top down world avoiding the red tiles.
EDIT: the problem was that collision point returns an id. so I have changed it to a x and y coord comparison structure. it works fine now.
I even managed to figure out how to make it change animation sequences based on movement. now I will have to figure out how to have it stop charging when it collides with the player. I think I may need to use a finite state machine for the enemy.
But now I am trying to make a ram enemy that moves up and down to line up 10% of y with player and then charge towards the player on the x axis.
my movement code for the ram is the following
Code:
if (collision_point(sign(obj_player.x-x)64-x,y,obj_player,false,false)) {
phy_position_x += 32/3;
image_speed = .25;
} else if (collision_point(x,sign(obj_player.y-y)64-y,obj_player,false,false)) {
phy_position_y += sign(obj_player.y - y)*spd;
image_speed = .25;
} else {
image_speed = 0;
image_index = 1;
}
the game looks like this, you walk on a platform in a top down world avoiding the red tiles.
EDIT: the problem was that collision point returns an id. so I have changed it to a x and y coord comparison structure. it works fine now.
Code:
/// Move towards the player
var vspd = 0;
if abs(phy_position_x-obj_player.x) <= 64 and abs(phy_position_y-obj_player.y) <= sprite_height/10 {
spd = 3;
hspd = sign(obj_player.x-phy_position_x) * spd;
phy_position_x += hspd;
} else {
var hspd = 0;
}
if abs(phy_position_y-obj_player.y) >= sprite_height/10 and abs(phy_position_x-obj_player.x) <= 64 {
vspd = sign(obj_player.y-phy_position_y) * spd;
phy_position_y += vspd;
} else {
var vspd = 0;
}
event_inherited();
var dirx = sign(obj_player.x - x);
var diry = sign(obj_player.y - y);
if sign(hspd) = -1 and abs(vspd) < abs(hspd) {
sprite_index = spr_enemy_ram_left;
} else if sign(hspd) = 1 and abs(vspd) < abs(hspd) {
sprite_index = spr_enemy_ram_right;
}
if sign(vspd) = 1 and abs(vspd) > abs(hspd) {
sprite_index = spr_enemy_ram_down;
} else if sign(vspd) = -1 and abs(vspd) > abs(hspd) {
sprite_index = spr_enemy_ram_up;
}
Last edited by a moderator: