Inverted Controls when doing horizontal collisions in gamemaker studio 2

55 views Asked by At

SO like i tried to do horizontal collisions and the keys keep getting inverted

// step event

> **# `
>  `if left key pressed`
   if dleft = true
> > # {
> x += 2;
> `collsion left`
> if place_meeting(x + 12,y,Ground)
> > # {
> x += 3
> > # }
> 
> 
> > # }
> `if right key pressed`
> if dright = true
> > # {
> x -= 2;
> `collision right`
> if place_meeting(x + 12,y,Ground)
> > # {
> x -= 3;
> > # }
> 
> 
> > # }**
> 
> > `

I'm not a proffesional gml programer by the way

1

There are 1 answers

6
Steven On

This is because you do x += 2 when pressing left. Which means you increase the x-axis by 2 pixels, turning your object to the right. Similairly, decreasing the x-axis will turn you to the left.

For the y-axis however, the reverse is true, increasing it will make you go down, and decreasing it will make you go up. I think that's where the confusion went.

In GMS2 (and probably most game engines) the center point is on the top-left, and by increasing both x and y, you're filling up the space by going to bottom-right. Think of it like reading a book, where you start at top-left.

See bottom example of how it should look like. I've also fixed some formatting to make it more readable:

//if left key pressed
if dleft = true
{
    x -= 2;
    //collision left
    if place_meeting(x - 12,y,Ground)
    {
        x -= 3
    }
}
//if right key pressed
if dright = true
{
    x += 2;
    //collision right
    if place_meeting(x + 12,y,Ground)
    {
        x += 3;
    }
}