• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM My enemies jump weird when moving straight.

B

Benvel

Guest
I've started HeartBeasts RPG tutorial series and I'm around P(24) rn.
I've had this problem with the slimes as they "jiggle" or shake between two positions when going forward.
First I thought that the problem was with them chasing the player and since I created my own sprites instead of downloading his ones, I figured the problem would be with the different center on my own player character.

But the problem is actually just with them walking forward.

My code is almost identical with his, except for the different animations, speeds, sprites and the absence of a dash state.

Has anyone else had this problem?
 
B

Benvel

Guest
- Here you go -

obj_slime:
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Event: Create
/// Initialize the slime
event_inherited();
image_speed = .1;
spd = 1;
state = scr_enemy_idle_state
alarm[0] = room_speed*irandom_range(2, 5);
sight = 96
targetx = 0;
targety = 0;

Event: Destroy
/// Create the experience
instance_create(x, y, obj_expr);

// Drop a health pack
if (scr_chance(.5))
{
instance_create(x+random_range(-9, 9), y+ random_range(-9, 9), obj_health);
}

Event: Alarm 0
/// Wander Alarm

Event: Alarm 1
/// Stall Alarm

Event: Step
/// Run the current state.
event_inherited();
script_execute(state);

Event: Player Collision
/// Damage the player

if (state != scr_enemy_stall_state)

{
var dir = point_distance(other.x, other.y, x, y);
var xdir = lengthdir_x(1, dir);
var ydir = lengthdir_y(1, dir);
var damage = instance_create(other.x+xdir, other.y+ydir, obj_damage);
damage.creator = id;
damage.knockback = 5;
state = scr_enemy_stall_state;
alarm[1] = 20;
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
///scr_enemy_idle_state()

scr_check_for_player();
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
///scr_check_for_player()

if (instance_exists(obj_player))
{
var dis = point_distance(x, y, obj_player.x, obj_player.y);
if (dis < sight)
{
state = scr_enemy_chase_state;
targetx = round(obj_player.x)
targety = round(obj_player.y)
}
else
{
scr_enemy_choose_next_state();
}
}
else
{
scr_enemy_choose_next_state();
}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
///scr_enemy_chase_state()

scr_check_for_player();
var dir = point_direction(x, y, targetx, targety)
var hspd = lengthdir_x(spd, dir)
var vspd = lengthdir_y(spd, dir)
if (hspd != 0)
{
image_xscale = sign(hspd);
}
phy_position_x += round(sign(targetx - x)*spd);
phy_position_y += round(sign(targety - y)*spd);
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
///scr_enemy_choose_next_state()

if (alarm[0] <= 0)
{
state = choose(scr_enemy_wander_state, scr_enemy_idle_state);
alarm[0] = room_speed*irandom_range(2, 4);
targetx = round(random(room_width));
targety = round(random(room_height));
}

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
///scr_enemy_wander_state()

scr_check_for_player();
if (point_distance(x, y, targetx, targety) > spd)
{
var dir = round(point_direction(x, y, targetx, targety))
var hspd = lengthdir_x(spd, dir)
var vspd = lengthdir_y(spd, dir)
if (hspd != 0)
{
image_xscale = sign(hspd);
}
phy_position_x += round(sign(targetx - x))*spd;
phy_position_y += round(sign(targety - y))*spd;
}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
///scr_enemy_stall_state()

scr_check_for_player();
if (alarm [1] <= 0)
{
state = scr_enemy_idle_state;
}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 
Use his sprites and see if you still get that problem, if its fixed its a sprite origin issue with your sprites and if not you might have typed something wrong somewhere in the code.
Handy tip: make sure you truly understand what you type and not just copy paste, because whenever problems/bug will occur (and they will) you will be clueless on what to do if you don't understand what you are looking at (or maybe you do! just saying ;))
 
B

Benvel

Guest
Use his sprites and see if you still get that problem, if its fixed its a sprite origin issue with your sprites and if not you might have typed something wrong somewhere in the code.
Handy tip: make sure you truly understand what you type and not just copy paste, because whenever problems/bug will occur (and they will) you will be clueless on what to do if you don't understand what you are looking at (or maybe you do! just saying ;))
I have been paying attention. I wasn't just copying.
When the bug occurred I fiddled with it a lot trying to make it work (This was a few years ago).
But soon after I decided that it wasn't game braking and that I could leave it as it is and keep on going.

After that there was a long pause of about a year or two I quickly examined my code and kept on going from where I left off.
Now that the project is nearing completion I realized how much the bug bothered me.

In hindsight I have a made a bunch of mistakes with this project, for instance me making my own sprites stubbornly and the fact that I didn't try harder when the bug first occurred.

I'll do what you suggested when I have time. I code on weekly intervals.
 
Top