• 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!

About enemy objects' movement speed...

So. This might have the easiest solution to it that i just cant figure out, but: i have this TDS game where an enemy object has two stances, patrolling and attacking. Patrolling means it gets a random direction and speed, and starts going around the level. (in Step Event) Then when the time comes, or when it sees the player, it attacks, meaning it gets the mp_potential_step -code in the Step event, and the patrolling-variable turns to zero. However, it still somehow counts the patrolling speed ON TOP of the attacking speed, resulting in the enemy object rushing at the player crazy fast. I just cant find out how to prevent it from adding the patrolling speed to the attack speed, i mean, the patrolling variable is turned to 0 when it attacks, so it shouldn't even take the patrolling speed into consideration anymore?
I tried moving the patrolling event to Step End, but that didnt help. Would moving it to Step Begin do the trick, didn't get to try it out yet...
So yeah, i'd just want to know how to make the enemy object not add the attack speed on top of the 'patrol' speed when it finally attacks, just switch to the attack speed.
Thanks beforehand. Hope its not too complex.
 
It's hard to say without seeing your code :)

I doubt it's anything complex, but with no knowledge of what you're doing it's difficult to figure out the cause of the issue.

Off the top of my head: I know there are some functions (add_speed? Something along those lines. I'm not in GMS right now to check) that are quite literal, and will stack on top of other functions that do speed too. I'm not sure if once you've set them they don't just carry on as a permanent value, and need manually resetting afterwards. Speed = 0 etc, else it persists....??

Or you could be repeating the circumstances that are calling this speed addition, and then its doing the mp_potential_step code immediately afterwards.

Seeing the code will really help :)
 
So for patrolling i use the code motion_set, or the Action 'Move Free'
For attacking i use the code mp_potential_step.
The Step event of the enemy has a lot of actions, not only a single long script of code or two, so its hard to recreate here...
But yeah, i guess its worth trying to set the speed to 0 first when it changes from patrol to attack?
 
Without seeing your code it's impossible to answer that. But, if you are finding the instance is moving faster than you expect it to, there can only be so many reasons for it. These are my theoretical suggestions:

1) Mp_potential_step gives a different result to how objects move under other functions? I don't know - I don't really use the function, and would have to test it
OR
2) It does treat movement the same, and you maybe have it set to the wrong speed? Or are calling it too often?

Example: if you called it within the begin step, step, and end step, it would maybe triplicate the distance traveled, as each calling stacks on the previous one.....
OR
3) Mp_potential_step is being affected by values from the other movement type. Either because they are still active in the code block (not as "switched off" as you believe), or because the value they give still persists.

I'd have to test all of these out, as it's just a guess right now.

EDIT:
Regarding number 1. Mp_potential_step moves exactly the same distance as any other movement type

EDIT 2:
The example given in number 2 is correct. Calling it in more than one step event will increase the distance it covers. It only needs calling once per step.

EDIT 3:
Regarding number 3. When Mp_potential_step is being done, and an instance also has its speed and direction set, it will "stack" on top. I started two objects at the same point, and both had the same speed and direction. One was also doing mp_potential_step, and it moved faster than the one that did not have it.

Using motion_set I saw the same result as to when I set its direction and speed. It would seem that speed is something you need to set to zero before calling mp_potential_step, else it persists as a value.
 
Last edited:

woods

Member
in the create event set speed to zero
in each of the states, set speed to whatever

another thought i recently learned the difference between = and == that could be the issue as well
 
thank you all. if these don't solve it somehow then i will try and recreate the chain of Actions of the object here. its a long Event composed of a mixture of codes and Actions, but come to think of it, maybe i could just try and write it all into a single long code in the Step event, obviously would be easier to manage the Event.
 
Hey again, problem solved, setting the speed to 0 at the beginning of each movement code solved the issue. was that simple all along! thanks to all.
 
Top