#### wilmer

##### Member

**Greetings to all:**

I am basing myself on some tutorials to make slopes for my platform game, the problem is that the tutorials are made in GMS 1.4 and I am doing it in GMS 2, and there are boxes in the GMS 1.4 sprite editor that are not in GMS2 and when my character passes or jumps over the sloping ground it detects its rectangular collision mask and does not advance diagonally. I'm talking about these from Collision Checking:

It happens that, my sprites for the ground and slopes, have proportions superior and irrelevant to the one in the tutorial and in it the two boxes under Collision Checking are marked and now I don't know if these options were replaced by functions in the GML and if it is viable make slopes in my project with this code:

The code works like this: All collision code is placed on the character and block objects must be created for the floor types (the floor that is flat, the slopes and also slopes that are steeper), and there will be a main floor block that will be the father of the other blocks.

**Create Event:**

Code:

```
intVY = 0;
intVX = 0;
intMove = 0;
intMultiplier = 1.0
intVYMax = 9 * intMultiplier;
intVXMax = 6.5 * intMultiplier;
intJumpHeight = 8 * intMultiplier;
intGravityNorm = 0.5 * intMultiplier;
intGroundAcc = 1.0 * intMultiplier;
intGroundFric = 1.9 * intMultiplier;
intAirAcc = 0.75 * intMultiplier;
intAirFic = 0.1 * intMultiplier;
```

**Step Event:**

GML:

```
var keyLeft, keyRight, keyJump, keyJumpRelease;
keyLeft = -keyboard_check (vk_left);
keyRight = keyboard_check (vk_right);
keyJump = keyboard_check_pressed (ord ("X"));
keyJumpRelease = keyboard_check_released (ord ("X"));
// Collision Check
intColLeft = place_meeting (x - 1, y, objBlock);
intColRight = place_meeting (x + 1, y, objBlock);
bolGround = place_meeting (x, y + 1, objBlock);
intMove = keyLeft + keyRight;
// Define acceleration and friction as a function of the medium
if (! bolGround)
{
intTempAcc = intAirAcc;
intTempFric = intAirFic;
}
else
{
intTempAcc = intGroundAcc;
intTempFric = intGroundFric;
}
// horizontal speed
if (intMove! = 0) intVX = scrApproach (intVX, intVXMax * intMove, intTempAcc);
else intVX = scrApproach (intVX, intVXMax * intMove, intTempFric)
// vertical speed
if (! bolGround)
{
intVY = scrApproach (intVY, intVYMax, intGravityNorm); //Freefall
}
//Jump
if (keyJump && bolGround) intVY = -intVYMax;
// horizontal collision
repeat (abs (intVX))
{
// Slope - Uphill
if (place_meeting (x + sign (intVX), y, objBlock) && place_meeting (x + sign (intVX), y-1, objBlock) && place_meeting (x + sign (intVX), y -2, objBlock) &&! place_meeting (x + sign (intVX), y -3, objBlock)) y - = 3;
else if (place_meeting (x + sign (intVX), y, objBlock) && place_meeting (x + sign (intVX), y-1, objBlock) &&! place_meeting (x + sign (intVX), y -2, objBlock)) y - = 2;
else if (place_meeting (x + sign (intVX), y, objBlock) &&! place_meeting (x + sign (intVX), y -1, objBlock)) y--;
// Slope -Downhill
if (! place_meeting (x + sign (intVX), y, objBlock) &&! place_meeting (x + sign (intVX), y + 1, objBlock) &&! place_meeting (x + sign (intVX), y + 2, objBlock) &&! place_meeting (x + sign (intVX), y + 3, objBlock) && place_meeting (x + sign (intVX), y + 4, objBlock)) y + = 3;
else if (! place_meeting (x + sign (intVX), y, objBlock) &&! place_meeting (x + sign (intVX), y + 1, objBlock) &&! place_meeting (x + sign (intVX), y + 2, objBlock ) && place_meeting (x + sign (intVX), y + 3, objBlock)) y + = 2;
else if (! place_meeting (x + sign (intVX), y, objBlock) &&! place_meeting (x + sign (intVX), y + 1, objBlock) && place_meeting (x + sign (intVX), y + 2, objBlock) ) y ++;
if (! place_meeting (x + sign (intVX), y, objBlock))
{
x + = sign (intVX);
}
else
{
intVX = 0;
break;
}
}
// Vertical collision
repeat (abs (intVY))
{
if (place_meeting (x, y + sign (intVY), objBlock))
{
intVY = 0;
break;
}
else y + = sign (intVY);
}
```

Code:

Last edited: