I'm stuck with my Collision code for the sloped floor ( SOLVED )

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:
1608942442889.png

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:

wilmer

Member
Did you somehow manage to declare a variable called "and"? If so, why? If not, why are you treating it like a variable?
Oh sorry, that's what happens when you use Google translate, it's not "and" it's a "Y". XD
 
Last edited:

Nidoking

Member
Are both the ground block and the character sprite set to precise collision checking? I think it only works if both sprites are set that way.
 

wilmer

Member
Are both the ground block and the character sprite set to precise collision checking? I think it only works if both sprites are set that way.
If I finished trying but it didn't work either, however I hadn't mentioned that my character's sprite is animated in Spine 2D, so I tried a normal PNG sprite and it worked perfect, so the solution will be for me to export my character Spine 2D with PNG image sequences.
 

kburkhart84

Firehammer Games
Oh sorry, that's what happens when you use Google translate, it's not "and" it's a "Y". XD
Must be Spanish, unless another language uses the single letter 'Y' for the word and.

If I finished trying but it didn't work either, however I hadn't mentioned that my character's sprite is animated in Spine 2D, so I tried a normal PNG sprite and it worked perfect, so the solution will be for me to export my character Spine 2D with PNG image sequences.
I'm no expert on Spine 2d sprites...but I thought they generally worked like normal sprites as far as setting collision masks. If they simply can't have collision masks for some reason, you could always code it with the PNG(empty square) as far as collision, and have the draw event draw your Spine2d thing. The draw event can draw anything you want, whether that includes the sprite you have set on the object or not.
 
Top