Which part of the manual page is unclear?Can you give me some examples
When you use this you are effectively asking GameMaker Studio 2 to move the instance to the new position, check for a collision, move back and tell you if a collision was found or not.
if keyboard_check(vk_left)Which part of the manual page is unclear?
When posting code use the code formatting tool of the forum:if keyboard_check(vk_left)
{
if !place_meeting(x - 5, y, obj_wall) x -=5;
}
Can you explain "x-5"?
// If the left arrow key is down
if keyboard_check(vk_left) {
// Check if I dont collide with any obj_wall when I move 5 units to the left (x-5)
if (!place_meeting(x - 5, y, obj_wall)) {
// Then go ahead and actually move 5 units to the left (x -= 5)
x -= 5;
}
}
If I (an instance) is not "place_meeting" (overlapping, roughly) an obj_wall instance if i were 5 pixels to the left of my current position, move me (an instance) 5 pixels to the left.if keyboard_check(vk_left)
{
if !place_meeting(x - 5, y, obj_wall) x -=5;
}
Can you explain "x-5"?
x - 5
is because they want to check as if the instance were sitting 5 pixels to the left. If there is no overlap (which is where the !
or not comes in, basically saying if place_meeting is NOT true), then the instance gets moved to that position: x -= 5;
.- 5
, for example:if !place_meeting(x,y,obj_wall) {
// Do stuff
}