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

Stopping player from moving

K

kmce

Guest
I want to stop the player from moving when they have touched a specific objects.

The code I have for the player to move is
x-=5;
x+=5;
same with the Y

So I have a variable set up called move. it is originally set to 1, once the player touches the object the variable move is set to 0, then in a step event I have
x-=0;
x+=0;
same with Y

But this does not stop the player from moving. Does anyone know another way in which i could set it up, or maybe know whats wrong with the code I have
 

FrostyCat

Redemption Seeker
What do you want from this, really?

Your first piece of code moves left 5 pixels and then right 5 pixels. This does absolutely nothing.

Your second piece of code moves left 0 pixels and then right 0 pixels. This also does absolutely nothing.

This is what happens when you take code out of context and expect us to draw conclusions from it. How about you paste your actual code along with which event you put them in, instead of telling us what you think your code does?
 
K

kmce

Guest
What do you want from this, really?

Your first piece of code moves left 5 pixels and then right 5 pixels. This does absolutely nothing.

Your second piece of code moves left 0 pixels and then right 0 pixels. This also does absolutely nothing.

This is what happens when you take code out of context and expect us to draw conclusions from it. How about you paste your actual code along with which event you put them in, instead of telling us what you think your code does?
Is it needed to be so rude?
 
K

kmce

Guest
Code shows exactly what i said.

collision event makes variable move = 0
 

Attachments

Xer0botXer0

Senpai
Hmm it does seem fruitless, gml is big and its exciting to go through the different sections of the manual to see what there is !

Something you need to know is that code is run from top to bottom. So x+=5 will increment your object instance by five pixels.. then x-=5 will run and decrement it by five. This then does not stop the speed rather jumps right and left in every step. A step is basically one iteration of game code, steps are based on room speed where if room_speed = 30 then 30 steps will run per a second.

So if you dont encapsulate
speed =0;
In a collision event and just leave it in the step event then your object instance will not move, and it may conflict with other code that makes it move.

So for example
Say your object instance is at x50,y300
Step event:

If distance_to_point(150,300) < 5
{speed=0}
Move_towards_point(200,300,5)

The above code will move your instance to x200,y300 and at the speed of 5 (pixels per step?) .. now theres a condition thats that is tun every step.. if your object instance is within the specified pixels of the specified x/y position then ..stop.

You also need to be careful about the order in which you write code.
 

Jakylgamer

Member
to prevent movement just do a check before you move
Code:
if (!place_meeting(x+5,y,obj_dev_block)) {
   x+=5;
}
do that for all the directions changing the x+5 in the place meeting check to the direction you are going
 

Xer0botXer0

Senpai
Setting x=0 and y=0 wont stop your object instance, it will teleport/ move it to the 0,0 coordinates.

X,Y and Z are cartesian coordinates. Variables to represent positions in either 2/3 dimensional space.
 

FrostyCat

Redemption Seeker
Your problem is failing to stop the movement at the source, namely the WASD keys. You have to put the checks for move there, not in the Step event and definitely not putting it in charge of pointless nonsense like adding/subtracting 0.

Here is an example for your S key:
Code:
if (move) {
  y += 5;
}
Repeat for your other movement keys.
 
Top