You all prolly dont care but does someone know a way to log back into an instagram account? I was dumb lost my password. I appreciate any help you can give me.
@Ayden Liam i really appreciate your reply. I got to the site thru google and I'm trying it out atm. I see it takes a while so I will get back to you later with my results.
Thanks for all of your hard work on this series and for providing all the assets for us to follow along! One thing that bothered me was the way we initialized the scripts for each of the enemy states (20:43 for reference). After some research, I learned that enums don’t support any sort of length operation, so the way you did it makes sense. One suggestion I found was to have to the last entry in an enum be “length”, so that way it can be referenced to loop over all of the entries in a normal for loop and it will also update for free if we add a new state.
Hi ! Thank you for all this work ! It's amaizingly helpful !!! I follow your RPG tutorial serie since the beegining and thanks to you my game is looking better every week !
This is immensely helpful! Please don't stop) it is great to see a bit more advanced processes of how to set up a bigger game rather than just a beginner project. If you ever decide to make a video about your ideas and ways of structuring a project, i would be glad to watch it) I find that project planning is really hard and as i work on mine there are always things that come up during work that i haven't accounted for so i have to replan on the fly which is a hassle.
IF YOUR SLIME IS NOT MOVING Make sure that the else statement here is in the correct spot: 23:22 If it's attached to the "if (++wait >= waitDuration)" statement, it is in the wrong spot and the code will not execute as intended. It MUST be attached to the main if statement
My else statement is in the correct spot attached to tha main if statement, but my slime isn't moving. Is there something else, that may cause the problem?
It would be really cool if objects could be groups, so we could have pEntity that expands to all entities including pEnemy, which expands into all enemies. And a new right click menu option for making a child object, which places it into the group of that object automatically.
Nice! I'm excited for the continuation of the enemy code! Oh yeah also my slime for some reason is only going Northeast as well, I don't know what to do about that.
@@SaraSpalding I re-watched this video and checked all of the new code added from the video twice and I still don't understand what I did wrong for the Slime to keep moving Northeast.
is your irandom_range(-45,45) correct? Just a guess, but Northeast is 45 degrees in GML. The line should be: dir = point_direction(x, y, xstart, ystart) + irandom_range(-45, 45);
@@SaraSpalding I've redoing the things in this video and this is what I have for the SlimeWander script: (Is there something I'm not seeing?) sprite_index = sprMove; //At destination or given up? if ((x == xTo) && (y == yTo)) || (timePassed > enemyWanderDistance / enemySpeed) { hSpeed = 0; vSpeed = 0; //End our move animation if (image_index < 1) { image_speed = 0.0; image_index = 0; } //Set new target destination if (++wait >= waitDuration) { wait = 0; timePassed = 0; dir = point_direction(x,y,xstart,ystart) + irandom_range(-45, 45); xTo = x + lengthdir_x(enemyWanderDistance, dir); yTo = y + lengthdir_y(enemyWanderDistance, dir); } } else //Move towards new location { timePassed++; image_speed = 1.0; var _distanceToGo = point_distance(x,y,xTo,yTo); var _speedThisFrame = enemySpeed; if (_distanceToGo < enemySpeed) _speedThisFrame = _distanceToGo; dir = point_distance(x,y,xTo,yTo); hSpeed = lengthdir_x(_speedThisFrame, dir); vSpeed = lengthdir_y(_speedThisFrame, dir); if (hSpeed != 0) image_xscale = sign(hSpeed);
I made a function TileCollision when I made entity collisions and applied it to fragment collisions. They all use the same collisions, including enemies.
Also would love to know, I've tried several ways by looking at how the player changes directions, but I'm pretty terrible at this I guess because nothing works.
@@a1zombieslayer148 Not yet, I might revisit it when I get better at this, I just moved on to other parts of the game for now. I'm sure it's easy if you know what you're doing.
@@miguelgrifo2198 I appreciate the response i used to be good in gml 8.1 and knew how to do it but gml has changed since those days. I got it to almost work by separating the sprites into directions but since the object can move in a 45° angle it may be fixed with an 8 directional sprite or calling the angle and telling it to pick based off which number is greater
I use an enemy with more than 4 frames. How do I have him face the correct direction? When he dies he plays all 16 death frames as well. (4 per direction) any help on both of these problems?
Anyone else having issues with the slimes occasionally teleporting and getting stuck inside of or on the other side of walls? I can't tell if this is related to the slime's original movement code, or the later chase and attack codes. Anyone know what might be causing this problem?
If anybody wanted to make their slime move a random amount instead of the exact same distance every single time, you could try adding < enemyWanderDistance = random_range(0, 45); > And make it the first command in < if (++wait >= waitDuration) { > in the SlimeWander script You could also try messing with the variables to make it easy to change per entity, and I'm willing to bet there's way better ways of doing this than what i thought of
Okay I figured out a pretty simple way to make it modular! Go to pEntity > Create and in Intrinsic variables add enemyWanderDistance = 35; Then go to variable definitions and rename enemyWanderDistance to enemyWanderMinMax, and change the definition to [0, 45] Then go to your SlimeWander script, and under //Set new target destination, make it look like if (++wait >= waitDuration) { enemyWanderDistance = random_range(enemyWanderMinMax[0], enemyWanderMinMax[1]); wait = 0; timePassed = 0; ... Etc ... Etc Basically you're making enemyWanderDistance a static variable in the beginning and changing it to a random number when setting a new target destination
Just a quick question, I am not sure if this is mentioned later in the series, but shouldn't it better to set the collision mask for the slime? Since it checks for the collisions and could cause some problems.
Ok, so I ran into this issue. If your slime isn't moving, make sure oSlime: Create is writing to enemyScript, not Script, I had that error because I looked away when the full word was showing.
Man I love this series so much. Just a small thing I noticed, am I correct that 'dir = point_direction(x,y,xTo,yTo);' when moving to the new destination in 'Slime Wander' is redundant? dir has already been set when determining the new target destination.
when i disabled the dir = line in the slime wander moving to a new destination block, my slime stopped only trying to move up and left until it hit a wall and instead started moving around in a seemingly random pattern like it did in shauns video
oh my gosh I figured it out! This was driving me crazy! Check your EnemyTileCollision script and make sure at the end after you check for vertical collisions you have "y += vSpeed" NOT "hSpeed". I copy/pasted and seems I forgot to change it. That fixed it for me!
my slime is just squishing and then playing the idle animation. it's not going places. does anyone know how to stop these? edit: i needed to included "EnemyTileCollision();"
I had a problem where the slime keept running to the top right swaping enemyWanderDistance and dir (where you set your destination) helped xTo = x + lengthdir_x(dir, enemyWanderDistance); yTo = y + lengthdir_y(dir, enemyWanderDistance);
Hi there! Thanks for these tutorials. Question for the comments section: my slime is animated, but isn't moving anywhere. I've checked through every line of code from this tutorial and the only difference I can spot is that "_collision" in EnemyTileCollision is yellow, not blue. That suggests it's a different type of thing, but I have no idea why, or whether that could be causing my slime to not move.
Hey so I know I am a little late but I had the same issue as you. I fixed it by adding x+=hSpeed and y+=vSpeed to the bottom of the respective collision code var _Collision = false;
//Horizontal Tiles if (tilemap_get_at_pixel(collisionMap, x + hSpeed, y)) { x -= x mod TILE_SIZE; if (sign(hSpeed) == 1) x += TILE_SIZE - 1; hSpeed = 0; _Collision = true; } x += hSpeed;
//Veritcal Tiles if (tilemap_get_at_pixel(collisionMap, x, y + vSpeed)) { y -= y mod TILE_SIZE; if (sign(vSpeed) == 1) y += TILE_SIZE - 1; vSpeed = 0; _Collision = true; } y+=vSpeed
@@redfoxpw6566 Deary me, that did help me out.. I've been looking in the code for hours to find the mistake, cheers! Didn't even think of adding something.
So my enemy is currently just the first frame moving around. I'm pretty sure I'll figure that bit out. But I have an idle animation I want to use also for when the enemy is pausing. Can anyone offer some ways to go about having a separate walk animation and idle animation with this same effect?
@@corzax24_plays7 I was trying to do my NPC the same as the player with four directional movement. That's why mine wasn't working. It works the right way if you follow the tutorial though
lmao I always copy the code through headphones and dont really watch the video, so i can focus on other things at the same time. And I set the variable as "weight" at first and "wait" later.
in the setting a new destination part, when you apply the formulas "xTo = x + lengthdir_x(enemyWanderDistance,dir);" and "yTo = y + lengthdir_y(enemyWanderDistance,dir);", when I execute it, it gives me an error in the part that tells me as if it were not declared, so I skip to that part because I am doing this part of the enemy, so if someone helps me solve that part it would be an honor.
If you have not defined vSpeed and hSpeed, then the Slime will not move. You have to add x += hSpeed and y += vSpeed to the top of the SlimeWander script. Was this helpful?
My slime is not animating can someone help?? I ran through all my code and copied his one-to-one. The slime moves around perfectly and its collision works as well so I don't know what I did to mess it up.
So in the wander script at the start it sets image_speed to 0.0 upon reaching its destination. That's what stops the animation, at least for me, because if i remove those lines the enemy will keep animating (and not stoping when idle). So somewhere the animation is supposed to be resumed again when the enemy is moved but i don't know how or where because it's not in the wander script.
I am so stuck...I have copied the code exactly as it is in the tutorial, and I have googled the issue and searched the comments to see if anyone else has this issue...but for what ever reason when the slime collides with the player it disappears and I cannot for the life of me figure out why and it seems as though I am the only one with this issue...please help... PS. LOVE LOVE LOVE the series, it has been phenomenal!!
Hi Shaun! Thank you so much for these videos, they are amazing. I am having trouble with this one! My enemy moves in 4 directions; I have created my equivalent of sSlime, sSlimeRun, in the same vein as we used sPlayer and sPlayerRun. I can not seem to figure out how to get him to wander! I have tried several things, but nothing seems to be working. Any help on how I can have my enemy wander with animations in 4 directions would be amazing. Either way, thank you again for making these videos. Really helping me move forward in my dream of creating a video game!
I'm trying for 8 directions myself. Remember CARDINAL_DIR? It has to have something to do with that. And when you talkto entities they face which ever direction activated. if we find a way to combine that logic with ENEMYSTATE.WANDER i think we will figure it out. like dir= cardinal_dir/8 and after that i'm lost lol. I'll keep trying.
my slime hits the wall and then spazes out trying to get away from the wall, but it get stuck and can't exit the tile. EDIT: i turned entityCollision on in the Varible Definitions (inherited from pEntity). once i turned that off, it no longer got stuck. i had it on because i wanted it to collide with pots and signs.. but it is not needed if those entities have their collision on (as a side note, i also have entity collision script from the player pasted into the slime cause i didn't want my creatures crawling over the liftable stones and stuff in the dungeons. it works properly now)
SLIME NOT MOVING ISSUE Like some others, my sprite is just staying in place rather than moving. I know my SlimeWander and EnemyTileCollision scripts are working correctly because the sprite moves fine if I change the pEnemy step event to just run SlimeWander(). This means the error must be something to do with this code in the step event, which I can tell is not running at all: if (enemyScript[state] != -1) { show_debug_message("Wander has been changed") //This never appears script_execute(enemyScript[state]); } I've triple checked that my code is the same as Sara's. Any ideas how to fix this?
Hello Shaun, I have been following your tutorial and just recently completed the melee hitbox video. I was curious if something in GameMaker Studio 2 changed because all of a sudden when I walk with my character the character sprite starts to vibrate. This vibration effect wasn't happening before.
I made sprMove a variable in the variable definitions with the type Asset, so I can choose the sprite from there instead of having to remember to put it in the create event. Although I still have to set all the scripts anyway. But if I forget the create event, the enemy just does nothing, but at least I'll see him.
couldnt figure out why my sprite was stretching randomly, then I realized I was typing while listening instead of watching and put sin(hspeed) not sign(hspeed)
Question from the future here! Basically, I want the player to be able to control different characters throughout the game. I thought to do this I would set all the code that is in oPlayer into a Parent object I've called pPlayerEntity, and have this little cat character inherit all of the code from that parent. First try and the player object just stands there with the sprite quickly moving through all of the frames making it look like its spinning in place for some reason. Has no ability to react to input, and is definitely not inheriting anything (I purposely started gutting the code of the parent to see if it would cause an error and nothing). I have no idea why the child just wont inherit the parent object code. I made sure it is set accordingly, I made sure I have no code in the child object so it has nothing to run BUT the parent code, and still nothing. I am completely stuck, any ideas? it seems to be an issue with inheritance that im missing
because if the orgin point of the sprite is inside of the tile you collide with, you can get stuck. so TileSize-1 makes it so you "collide" 1 pixel away from the tile.
Did anyone else have a problem where the enemy tile collision wasn't working? After it didn't work, I tried to be sure and call the original player collision script as well (which definitely works for the player), but that didn't work either. Something's amiss. I'll try and figure it out, but any help would be appreciated ^_^; edit: i'm dumb. wayy wayy back in p_entity's room start I messed up the "collision map" statement. ugggggh -_-;;;
I had this error and i solved it by removing "()" at my object creation code. enemyFunction[ENEMYSTATE.WANDER] = EnemiesWander"()"; he mention it next episode at 14:00
I hope this will be useful to someone. I copied the whole tutorial letter by letter, but I had an error at the very end. When I started my game, it immediately crashed after the slime tried to move. SOLUTION: I completely deleted the last line from EnemyTileCollision script ( return _collision; ) after I deleted that whole line, the game now works perfectly as in the video.
My enemies are using 8 directions. Somehow I have to implement CARDINAL_DIR to the wander script. Wish me luck. I shall return with the answer if i figure it out. If i don't....
@@jacob6387 with Shaun's teachings you can do it like I did. I made var _facing = point_direction(x,y,xTo,yTo); *And do you remember the old sprite variable from the oplayer animation episode? You can use that for the enemies as well 😊. So make another variable var _oldSprite = sprite_index;
@@GandalfofROCK Thank you! I was actually able to figure it out by adjusting the PlayerAnimateSprite Function and instead of inputs I had it based on direction using point_direction(x,y,xTo,yTo) I am still adjusting the enemy functions so I don't have to put EnemyAnimateSprite under each function for them and instead have it work at large unless I have a special animation that is 1 direction like the enemy death!
@@jacob6387 look at us! Coding!!! The cardinal for is a little janky after the update which sucks but I'm sure there's a way to fix that. Good luck on your game. See you in future comment sections
Are temporary variables actually more efficient if you're gonna be using them (almost) every step? It's constantly deleting variables in order to save a few bytes in between every step and then creating them again. I guess it makes them impossible to hack, but these temporary variables are never gonna be hacked anyway. If people are gonna cheat, they are gonna hack the most important permanent variables like health and money.
What is the next video going to be? one thing I'm looking forward to is a quest system for mission objectives. give the players a list of tasks to complete for them to progress through the game. collect items, kill a monster, move to a location, or talk to someone. then when all these are done, the next quest is triggered I hope this'll be soon
As I said, we'll be developing the enemy further letting him chase the player, hit the player, be hit BY the player, be destroyed by the player, etc. There's a lot to do here. We'll have "quest" flags and states eventually as you can tell from playing the demo, it won't be listed on the screen as objectives or whatever but you could easily derive that from the system if you've been understanding the tutorial =)
can anybody in the comments help me with the wander script for a platformer enemy. with gravity involved the enemies xstart, and ystart become kind of a nuissance and any suggestions for how i could implement the script to accomodate the wander direction while still using the variables about distance and speed... sorry if i sound like a total n00b but im just trying to work out how others problem solve...
could be an issue with the lifting code. I had something similar but with the slime sprite above player. The wander designation somehow confused gamemaker into thinking to use the lifting code, but cant throw, no idea why. Fixed by cutting liftimg code to pEnemy inherentence. can't lift enemies but its a fix. I also copied some code from comments in their "improvement" of lifting code. No idea why it happened somhow enums getting mixed up for something.
dont be dumb like me another thing that can be causing your slime to animate but not move is if in p_enemy step your 1st or second line is "if (global.gamePaused) it should be if (!global.gamePaused) very easy to miss that !
Anyone in 2024 and later wondering how to fix this error --- Variable .EnemyTileCollision(100128, -2147483648) not set before reading it. at gml_Script_SlimeWander (line 44) - var _collided = EnemyTileCollision(); --- Change var _collided = EnemyCollision(); to EnemyCollision(); Ignore collided variable and leave just the function in SlimeWander line 44 so it will look like this // Collide & Move EnemyColision();
You know your in for a ride when Shaun says "lets maximise the window"
You all prolly dont care but does someone know a way to log back into an instagram account?
I was dumb lost my password. I appreciate any help you can give me.
@Bobby Elian Instablaster ;)
@Ayden Liam i really appreciate your reply. I got to the site thru google and I'm trying it out atm.
I see it takes a while so I will get back to you later with my results.
@Ayden Liam It did the trick and I actually got access to my account again. Im so happy:D
Thanks so much, you really help me out :D
@Bobby Elian You are welcome xD
You have a great things going, I love your content!
Thanks for all of your hard work on this series and for providing all the assets for us to follow along!
One thing that bothered me was the way we initialized the scripts for each of the enemy states (20:43 for reference). After some research, I learned that enums don’t support any sort of length operation, so the way you did it makes sense. One suggestion I found was to have to the last entry in an enum be “length”, so that way it can be referenced to loop over all of the entries in a normal for loop and it will also update for free if we add a new state.
you don't know how stoked I was when you said we'd be doing the wander func 16mins into the vid XD Cheers bro
Hi ! Thank you for all this work ! It's amaizingly helpful !!!
I follow your RPG tutorial serie since the beegining and thanks to you my game is looking better every week !
so stoked on this episode! been looking forward to this one the most!
This is immensely helpful! Please don't stop) it is great to see a bit more advanced processes of how to set up a bigger game rather than just a beginner project. If you ever decide to make a video about your ideas and ways of structuring a project, i would be glad to watch it) I find that project planning is really hard and as i work on mine there are always things that come up during work that i haven't accounted for so i have to replan on the fly which is a hassle.
Hello past Shaun! :D 10:26 thanks for all your help :)
Ur pulling me through game design bro ❤️
Hey Shaun, good tutorial on enemies. I just wanted to ask, where did you learn all of this stuff? Lol because I basically learn everything from you.
He have years of experiences
Great and informative video as always! Keep being awesome!
IF YOUR SLIME IS NOT MOVING
Make sure that the else statement here is in the correct spot: 23:22
If it's attached to the "if (++wait >= waitDuration)" statement, it is in the wrong spot and the code will not execute as intended.
It MUST be attached to the main if statement
Which statement
My else statement is in the correct spot attached to tha main if statement, but my slime isn't moving. Is there something else, that may cause the problem?
Can't wait for the continuation of this! :)
Love the series!
It would be really cool if objects could be groups, so we could have pEntity that expands to all entities including pEnemy, which expands into all enemies. And a new right click menu option for making a child object, which places it into the group of that object automatically.
I added a maxChaseDistance (state RETURNING). So you can run from your enemies :P
Nice! I'm excited for the continuation of the enemy code!
Oh yeah also my slime for some reason is only going Northeast as well, I don't know what to do about that.
Unsure about that, as you can see it doesn't in the video so double check your work! Make sure you understand how it all should work.
@@SaraSpalding I re-watched this video and checked all of the new code added from the video twice and I still don't understand what I did wrong for the Slime to keep moving Northeast.
is your irandom_range(-45,45) correct? Just a guess, but Northeast is 45 degrees in GML. The line should be:
dir = point_direction(x, y, xstart, ystart) + irandom_range(-45, 45);
My line of code is exactly like what you showed and it's still going NE
@@SaraSpalding I've redoing the things in this video and this is what I have for the SlimeWander script: (Is there something I'm not seeing?)
sprite_index = sprMove;
//At destination or given up?
if ((x == xTo) && (y == yTo)) || (timePassed > enemyWanderDistance / enemySpeed)
{
hSpeed = 0;
vSpeed = 0;
//End our move animation
if (image_index < 1)
{
image_speed = 0.0;
image_index = 0;
}
//Set new target destination
if (++wait >= waitDuration)
{
wait = 0;
timePassed = 0;
dir = point_direction(x,y,xstart,ystart) + irandom_range(-45, 45);
xTo = x + lengthdir_x(enemyWanderDistance, dir);
yTo = y + lengthdir_y(enemyWanderDistance, dir);
}
}
else //Move towards new location
{
timePassed++;
image_speed = 1.0;
var _distanceToGo = point_distance(x,y,xTo,yTo);
var _speedThisFrame = enemySpeed;
if (_distanceToGo < enemySpeed) _speedThisFrame = _distanceToGo;
dir = point_distance(x,y,xTo,yTo);
hSpeed = lengthdir_x(_speedThisFrame, dir);
vSpeed = lengthdir_y(_speedThisFrame, dir);
if (hSpeed != 0) image_xscale = sign(hSpeed);
//Collide & move
/*var _collided = */EnemyTileCollision();
}
I made a function TileCollision when I made entity collisions and applied it to fragment collisions. They all use the same collisions, including enemies.
Great tutorial! But i am having some troubles. My enemy keeps vibrating once it stops wandering. Anyone know how to fix this?
What would we change, if our enemy sprite is 4 direction like the player sprite?
if you discover, tell me please! hahaha
Also would love to know, I've tried several ways by looking at how the player changes directions, but I'm pretty terrible at this I guess because nothing works.
@@miguelgrifo2198 have you figured it out all i can get is the enemy to stop on the forth frame then continues going through 0,1,2,3 stop
@@a1zombieslayer148 Not yet, I might revisit it when I get better at this, I just moved on to other parts of the game for now. I'm sure it's easy if you know what you're doing.
@@miguelgrifo2198 I appreciate the response i used to be good in gml 8.1 and knew how to do it but gml has changed since those days. I got it to almost work by separating the sprites into directions but since the object can move in a 45° angle it may be fixed with an 8 directional sprite or calling the angle and telling it to pick based off which number is greater
I use an enemy with more than 4 frames. How do I have him face the correct direction? When he dies he plays all 16 death frames as well. (4 per direction) any help on both of these problems?
I know this is for a platformer but even if you're making a game like galaga it's very helpful!
Anyone else having issues with the slimes occasionally teleporting and getting stuck inside of or on the other side of walls? I can't tell if this is related to the slime's original movement code, or the later chase and attack codes. Anyone know what might be causing this problem?
If anybody wanted to make their slime move a random amount instead of the exact same distance every single time, you could try adding < enemyWanderDistance = random_range(0, 45); >
And make it the first command in < if (++wait >= waitDuration) { > in the SlimeWander script
You could also try messing with the variables to make it easy to change per entity, and I'm willing to bet there's way better ways of doing this than what i thought of
Okay I figured out a pretty simple way to make it modular!
Go to pEntity > Create and in Intrinsic variables add
enemyWanderDistance = 35;
Then go to variable definitions and rename enemyWanderDistance to enemyWanderMinMax, and change the definition to [0, 45]
Then go to your SlimeWander script, and under //Set new target destination, make it look like
if (++wait >= waitDuration)
{
enemyWanderDistance = random_range(enemyWanderMinMax[0], enemyWanderMinMax[1]);
wait = 0;
timePassed = 0;
... Etc
... Etc
Basically you're making enemyWanderDistance a static variable in the beginning and changing it to a random number when setting a new target destination
Just a quick question, I am not sure if this is mentioned later in the series, but shouldn't it better to set the collision mask for the slime? Since it checks for the collisions and could cause some problems.
Ok, so I ran into this issue. If your slime isn't moving, make sure oSlime: Create is writing to enemyScript, not Script, I had that error because I looked away when the full word was showing.
Thanks for the quick solution!
THANK YOU!
Very much appreciated man
Man I love this series so much.
Just a small thing I noticed, am I correct that 'dir = point_direction(x,y,xTo,yTo);' when moving to the new destination in 'Slime Wander' is redundant?
dir has already been set when determining the new target destination.
when i disabled the dir = line in the slime wander moving to a new destination block, my slime stopped only trying to move up and left until it hit a wall and instead started moving around in a seemingly random pattern like it did in shauns video
Here the slimes just go to the northeast direction, any clues why?
Unsure off the top of my head, let me know when you work it out!
oh my gosh I figured it out! This was driving me crazy! Check your EnemyTileCollision script and make sure at the end after you check for vertical collisions you have "y += vSpeed" NOT "hSpeed". I copy/pasted and seems I forgot to change it. That fixed it for me!
@@vintagetechno It didn't worked for me, my EnemyTileCollision is just like in the video :/
@@brunocolaco3188 dir=point_direction , not point distance. (in the slime wander script)
@@omniferousswan593 Thank you so much
my slime is just squishing and then playing the idle animation. it's not going places. does anyone know how to stop these? edit: i needed to included "EnemyTileCollision();"
I had a problem where the slime keept running to the top right
swaping enemyWanderDistance and dir (where you set your destination) helped
xTo = x + lengthdir_x(dir, enemyWanderDistance);
yTo = y + lengthdir_y(dir, enemyWanderDistance);
Hi there! Thanks for these tutorials. Question for the comments section: my slime is animated, but isn't moving anywhere. I've checked through every line of code from this tutorial and the only difference I can spot is that "_collision" in EnemyTileCollision is yellow, not blue. That suggests it's a different type of thing, but I have no idea why, or whether that could be causing my slime to not move.
Hey so I know I am a little late but I had the same issue as you. I fixed it by adding x+=hSpeed and y+=vSpeed to the bottom of the respective collision code
var _Collision = false;
//Horizontal Tiles
if (tilemap_get_at_pixel(collisionMap, x + hSpeed, y))
{
x -= x mod TILE_SIZE;
if (sign(hSpeed) == 1) x += TILE_SIZE - 1;
hSpeed = 0;
_Collision = true;
}
x += hSpeed;
//Veritcal Tiles
if (tilemap_get_at_pixel(collisionMap, x, y + vSpeed))
{
y -= y mod TILE_SIZE;
if (sign(vSpeed) == 1) y += TILE_SIZE - 1;
vSpeed = 0;
_Collision = true;
}
y+=vSpeed
@@redfoxpw6566 Deary me, that did help me out.. I've been looking in the code for hours to find the mistake, cheers! Didn't even think of adding something.
So my enemy is currently just the first frame moving around. I'm pretty sure I'll figure that bit out. But I have an idle animation I want to use also for when the enemy is pausing. Can anyone offer some ways to go about having a separate walk animation and idle animation with this same effect?
Did you figure the animation issue? Mine just moves around on a single frame too...
@@corzax24_plays7 I was trying to do my NPC the same as the player with four directional movement. That's why mine wasn't working.
It works the right way if you follow the tutorial though
try adding image_speed = 1 to the SlimeWander function (example below)
function SlimeWander(image_speed = 1){
lmao I always copy the code through headphones and dont really watch the video, so i can focus on other things at the same time. And I set the variable as "weight" at first and "wait" later.
in the setting a new destination part, when you apply the formulas "xTo = x + lengthdir_x(enemyWanderDistance,dir);" and "yTo = y + lengthdir_y(enemyWanderDistance,dir);", when I execute it, it gives me an error in the part that tells me as if it were not declared, so I skip to that part because I am doing this part of the enemy, so if someone helps me solve that part it would be an honor.
If you have not defined vSpeed and hSpeed, then the Slime will not move. You have to add x += hSpeed and y += vSpeed to the top of the SlimeWander script. Was this helpful?
The 2 links of code you mentioned are in the collisionscript he showed
My slime is not animating can someone help?? I ran through all my code and copied his one-to-one. The slime moves around perfectly and its collision works as well so I don't know what I did to mess it up.
Have you found any solution ? I’m stuck with that problem too.
@@leorigolo6194 i fixed , my error was Step event of pEnemy:
depth = -bbox_bottom;
i forgot the " ; " at the end line, hope works
So in the wander script at the start it sets image_speed to 0.0 upon reaching its destination. That's what stops the animation, at least for me, because if i remove those lines the enemy will keep animating (and not stoping when idle). So somewhere the animation is supposed to be resumed again when the enemy is moved but i don't know how or where because it's not in the wander script.
I fixed this by adding "image speed = 1;" within the "else" curly brackets { } but that might just be a temporary fix.
Woop i'm dumb, it's suppsoed to be there, so maybe you forgot to mess that line of code up too.
I am so stuck...I have copied the code exactly as it is in the tutorial, and I have googled the issue and searched the comments to see if anyone else has this issue...but for what ever reason when the slime collides with the player it disappears and I cannot for the life of me figure out why and it seems as though I am the only one with this issue...please help...
PS. LOVE LOVE LOVE the series, it has been phenomenal!!
Anyone having issues with the enemy animation in the Wander state? The animation doesn't play, he just moves around in a single still frame... :(
I have the same issue, have you figured anything out?
Just kidding! at the function of SlimeWander put "image_speed = 1"
for example: function SlimeWander(image_speed = 1){
Hi Shaun! Thank you so much for these videos, they are amazing.
I am having trouble with this one!
My enemy moves in 4 directions; I have created my equivalent of sSlime, sSlimeRun, in the same vein as we used sPlayer and sPlayerRun.
I can not seem to figure out how to get him to wander! I have tried several things, but nothing seems to be working. Any help on how I can have my enemy wander with animations in 4 directions would be amazing. Either way, thank you again for making these videos. Really helping me move forward in my dream of creating a video game!
I'm trying for 8 directions myself. Remember CARDINAL_DIR? It has to have something to do with that. And when you talkto entities they face which ever direction activated. if we find a way to combine that logic with ENEMYSTATE.WANDER i think we will figure it out. like dir= cardinal_dir/8 and after that i'm lost lol. I'll keep trying.
my slime hits the wall and then spazes out trying to get away from the wall, but it get stuck and can't exit the tile. EDIT: i turned entityCollision on in the Varible Definitions (inherited from pEntity). once i turned that off, it no longer got stuck. i had it on because i wanted it to collide with pots and signs.. but it is not needed if those entities have their collision on (as a side note, i also have entity collision script from the player pasted into the slime cause i didn't want my creatures crawling over the liftable stones and stuff in the dungeons. it works properly now)
SLIME NOT MOVING ISSUE
Like some others, my sprite is just staying in place rather than moving. I know my SlimeWander and EnemyTileCollision scripts are working correctly because the sprite moves fine if I change the pEnemy step event to just run SlimeWander().
This means the error must be something to do with this code in the step event, which I can tell is not running at all:
if (enemyScript[state] != -1)
{
show_debug_message("Wander has been changed") //This never appears
script_execute(enemyScript[state]);
}
I've triple checked that my code is the same as Sara's. Any ideas how to fix this?
it's about script_execute, but I'm struggling to find solution
/ Execute State Machine
if (!global.gamePaused) {
if (state >= 0 && state < array_length(enemyScript) && enemyScript[state] != noone) {
enemyScript[state]();
} else {
state = ENEMYSTATE.IDLE;
}
depth = -bbox_bottom;
}
find the solution, change the Step event for pEnemy
Hello Shaun, I have been following your tutorial and just recently completed the melee hitbox video. I was curious if something in GameMaker Studio 2 changed because all of a sudden when I walk with my character the character sprite starts to vibrate. This vibration effect wasn't happening before.
It's human error, not game maker.
I made sprMove a variable in the variable definitions with the type Asset, so I can choose the sprite from there instead of having to remember to put it in the create event. Although I still have to set all the scripts anyway. But if I forget the create event, the enemy just does nothing, but at least I'll see him.
My slime is just moving in place... anybody got in idea?
How could I change the code so that my slimes and enemys can animate in 4 directions like our player sprites?
I can show you what worked for me, I changed the bottom part of the EnemyWanderState:
else //Move Towards New Destination
{
timePassed++;
var _distanceToGo = point_distance(x,y, xTo,yTo);
var _speedThisFrame = enemySpeed;
if (_distanceToGo < enemySpeed) _speedThisFrame = _distanceToGo;
dir = point_direction(x,y,xTo,yTo);
hSpeed = lengthdir_x(_speedThisFrame,dir);
vSpeed = lengthdir_y(_speedThisFrame,dir);
}
//Collide & Move
EnemyTileCollision();
//Update Sprite / Image
//Update Sprite_Index
var _oldSprite = sprite_index
if (x != xTo) && (y != yTo)
{
direction = dir
sprite_index = spriteMove
} else sprite_index = spriteIdle
if (_oldSprite != sprite_index) localFrame =0
PlayerAnimateSprite();
}
couldnt figure out why my sprite was stretching randomly, then I realized I was typing while listening instead of watching and put sin(hspeed) not sign(hspeed)
The collision of my slime isn't working. He just walkes the walls. Can't figure out what i did wrong. Someone maybe got an idea?
through the wall*
Question from the future here!
Basically, I want the player to be able to control different characters throughout the game. I thought to do this I would set all the code that is in oPlayer into a Parent object I've called pPlayerEntity, and have this little cat character inherit all of the code from that parent. First try and the player object just stands there with the sprite quickly moving through all of the frames making it look like its spinning in place for some reason. Has no ability to react to input, and is definitely not inheriting anything (I purposely started gutting the code of the parent to see if it would cause an error and nothing). I have no idea why the child just wont inherit the parent object code. I made sure it is set accordingly, I made sure I have no code in the child object so it has nothing to run BUT the parent code, and still nothing. I am completely stuck, any ideas?
it seems to be an issue with inheritance that im missing
Hey, I am actually trying to do a very similar thing though I haven't started implementing that yet. Did you find a solution?
thank you
can anybody explain why its TILE_SIZE - 1; why it isnt just TILE_SIZE
if (sign(hSpeed) == 1) x += TILE_SIZE - 1;
because if the orgin point of the sprite is inside of the tile you collide with, you can get stuck. so TileSize-1 makes it so you "collide" 1 pixel away from the tile.
Did anyone else have a problem where the enemy tile collision wasn't working?
After it didn't work, I tried to be sure and call the original player collision script as well (which definitely works for the player), but that didn't work either. Something's amiss. I'll try and figure it out, but any help would be appreciated ^_^;
edit: i'm dumb. wayy wayy back in p_entity's room start I messed up the "collision map" statement. ugggggh -_-;;;
I had a similar issue, for me it was a typo i wrote collitionMap instead of collisionMap.
13:05 The depth is already set in the end step event of pEntity.
Did anyone get this error? script_execute argument 1 incorrect type (undefined) expecting a Number (YYGI32)
I had this error and i solved it by removing "()" at my object creation code.
enemyFunction[ENEMYSTATE.WANDER] = EnemiesWander"()";
he mention it next episode at 14:00
@@Eroseult thank you
I hope this will be useful to someone. I copied the whole tutorial letter by letter, but I had an error at the very end. When I started my game, it immediately crashed after the slime tried to move.
SOLUTION: I completely deleted the last line from EnemyTileCollision script ( return _collision; ) after I deleted that whole line, the game now works perfectly as in the video.
My enemies are using 8 directions. Somehow I have to implement CARDINAL_DIR to the wander script. Wish me luck. I shall return with the answer if i figure it out. If i don't....
Im just trying to do 4 directions, any progress?
@@jacob6387 with Shaun's teachings you can do it like I did. I made
var _facing = point_direction(x,y,xTo,yTo);
*And do you remember the old sprite variable from the oplayer animation episode? You can use that for the enemies as well 😊.
So make another variable
var _oldSprite = sprite_index;
@@GandalfofROCK Thank you! I was actually able to figure it out by adjusting the PlayerAnimateSprite Function and instead of inputs I had it based on direction using point_direction(x,y,xTo,yTo) I am still adjusting the enemy functions so I don't have to put EnemyAnimateSprite under each function for them and instead have it work at large unless I have a special animation that is 1 direction like the enemy death!
@@jacob6387 look at us! Coding!!! The cardinal for is a little janky after the update which sucks but I'm sure there's a way to fix that. Good luck on your game. See you in future comment sections
i haven't watched the whole series so i don't have pEntity, and the wander state isn't working, do i need pEntity or did i screw up else where?
I haven't been following either, I just added x = x+hSpeed and y = y+Vspeed and it works fine for me. (no collisions though, obviously)
Are temporary variables actually more efficient if you're gonna be using them (almost) every step? It's constantly deleting variables in order to save a few bytes in between every step and then creating them again. I guess it makes them impossible to hack, but these temporary variables are never gonna be hacked anyway. If people are gonna cheat, they are gonna hack the most important permanent variables like health and money.
What is the next video going to be? one thing I'm looking forward to is a quest system for mission objectives. give the players a list of tasks to complete for them to progress through the game. collect items, kill a monster, move to a location, or talk to someone. then when all these are done, the next quest is triggered
I hope this'll be soon
As I said, we'll be developing the enemy further letting him chase the player, hit the player, be hit BY the player, be destroyed by the player, etc. There's a lot to do here.
We'll have "quest" flags and states eventually as you can tell from playing the demo, it won't be listed on the screen as objectives or whatever but you could easily derive that from the system if you've been understanding the tutorial =)
can anybody in the comments help me with the wander script for a platformer enemy. with gravity involved the enemies xstart, and ystart become kind of a nuissance and any suggestions for how i could implement the script to accomodate the wander direction while still using the variables about distance and speed... sorry if i sound like a total n00b but im just trying to work out how others problem solve...
Somehow every slime I add to the room results in me getting another rotating player sprite on top of my head.
could be an issue with the lifting code. I had something similar but with the slime sprite above player. The wander designation somehow confused gamemaker into thinking to use the lifting code, but cant throw, no idea why. Fixed by cutting liftimg code to pEnemy inherentence. can't lift enemies but its a fix.
I also copied some code from comments in their "improvement" of lifting code. No idea why it happened somhow enums getting mixed up for something.
as my slime moves it squishes
Check lines with image_xscale. For example SlimeWander line 40
if (hSpeed != 0) image_xscale = sign(hSpeed);
Help please
Make one tutorial for game like rimworld (sorry for englhis erros im portugueses)
It's better to use waitDuration = gamespeed_fps;
Yo! Im early wow!
Nuuuuuhh im late
dont be dumb like me another thing that can be causing your slime to animate but not move is if in p_enemy step your 1st or second line is "if (global.gamePaused) it should be if (!global.gamePaused) very easy to miss that !
OH MY GOD THANK YOU. I HAVE BEEN READING COMMENTS FOR HOURS AND REWATCHING THE VIDEO. thanks you so much
Lmao! had this exact problem cheers mate
@@WiW14 cheers hope your game goes well!
@@a1zombieslayer148 thanks! I actually turned in the completed thing with a couple additions of my own for a school comp sci project :)
@@WiW14 hope you got an a!
Anyone in 2024 and later wondering how to fix this error
---
Variable .EnemyTileCollision(100128, -2147483648) not set before reading it.
at gml_Script_SlimeWander (line 44) - var _collided = EnemyTileCollision();
---
Change
var _collided = EnemyCollision();
to
EnemyCollision();
Ignore collided variable and leave just the function in SlimeWander line 44 so it will look like this
// Collide & Move
EnemyColision();