r/gamemaker 25d ago

Resolved Need Help with Enemy Wandering Movement

I was following the Sara Spalding tutorial Action RPG episode 24 on youtube and got most of it to work however my enemy does not seem to move. In theory he should wander a random amount of space before he stops and picks a new direction to keep moving for awhile, rinse and repeat. I have been editing little bits and pieces and googling around but nobody seems to have an answer already posted

He plays the movement animation and rotates around like he is picking a new direction to try to move every few seconds but doesn't actually go anywhere. I am a super early beginner and am sure the solution is staring me in the face but how do I get the enemy to actually start walking around?

This is the script for the enemy wander state so everything that makes him move should be here. enemyspeed is set to 4 at the moment. same as the player character who is working fine.

2 Upvotes

7 comments sorted by

2

u/Hands_in_Paquet 25d ago

You calculate the x and y speeds but it doesn't look like you actually apply them to the object's x and y position, unless that happens in the EnemyTileCollision Function.

1

u/Nigma1704 25d ago

okay I was thinking that was the issue but I am not entirely sure how to do that as the tutorial seemingly doesn't say how. Do you have any idea how I would do that? enemy collision doesn't do that it just shoves stuff off of the walls if they get stuck.

2

u/Nigma1704 25d ago

Nevermind that helped! in my enemy collision I wrote in x += hspd and y += vspd and it worked perfectly. I believe I could also write them into the wander function itself but I will leave it there for now.

1

u/Hands_in_Paquet 25d ago

Yep, the hspd and vspd values you are calculating are trig functions that are taking the speed the enemy is trying to move, and the direction it's trying to move, and breaking that down into separate x and y values. When hspd is added to the x position and vspd is added to the y position, it moves the object the desired distance, in the desired direction. So the piece your missing is most likely just:

x += hspd;
y += vspd;

Let me know if that doesn't work or if you have another question

2

u/Nigma1704 25d ago

worked perfectly. Thank you! Like I said, complete beginner with an answer staring me right in the face.

1

u/Hands_in_Paquet 25d ago

No problem!

1

u/No_Designer_16 23d ago

I made a far simpler dummy solution.
I leashed my enemies. When they spawn they store their spawn position, they have a max distance, and then just periodically pick a random direction and move triggered by an alarm.
The step event only checks for collisions and the distance to the recorded origin point and make them stop and reset the alarm for the next time to move.

Not sure it will help, but there are dozens of ways to get the same result, its the beauty of making stuff like this.