Tyron Deonarine
Member
Hello all, I need some help as i'm relatively new to GMS2.
I have a room 640x360, I have an object. I would like for that object to move randomly in the room. With the code I have, it's only moving left and right. Any guidance would be greatly appreciated. The code that I have currently is as below:
switch (state) {
#region Move Right
case slime.move_right:
var wall_at_right = place_meeting(x + 1, y, o_solid);
if (wall_at_right) {
state = slime.move_left;
}
//Direction of image
image_xscale = -1;
//Speed of image moving
x += 1;
break;
#endregion
#region Move Left
case slime.move_left:
var wall_at_left = place_meeting(x - 1, y, o_solid);
if (wall_at_left) {
state = slime.move_right;
}
//Direction of image
image_xscale = 1;
//Speed of image moving
x -= 1;
break;
#endregion
}
I have a room 640x360, I have an object. I would like for that object to move randomly in the room. With the code I have, it's only moving left and right. Any guidance would be greatly appreciated. The code that I have currently is as below:
switch (state) {
#region Move Right
case slime.move_right:
var wall_at_right = place_meeting(x + 1, y, o_solid);
if (wall_at_right) {
state = slime.move_left;
}
//Direction of image
image_xscale = -1;
//Speed of image moving
x += 1;
break;
#endregion
#region Move Left
case slime.move_left:
var wall_at_left = place_meeting(x - 1, y, o_solid);
if (wall_at_left) {
state = slime.move_right;
}
//Direction of image
image_xscale = 1;
//Speed of image moving
x -= 1;
break;
#endregion
}