S
Sokyogoku
Guest
Hi, I would like my game to have diagonal platforms. The problem is that I have little idea on how to add the code in. so far my character can go down these slopes but when going up them they seem to not have collisions.
I'm also kind of slightly above the beginner level but no more. The collision code I have from old Shaun Spalding's platformer tutorials (because I can't make my own and I couldn't find newer ones that include slopes).
To explain, variable collision 1 are solids and 2 are platforms. Mground is a variable to check if player is standing on any collision and is not in air. Vspd is vertical speed and hspd is horizontal speed.
I believe the issue is with this piece of code in horizontal collisions:
Because it only checks for the solid collisions. But at the same time it's the beginning for a collision check in which I want the player not to collide with platforms horizontally. How can I tweak this code so it'll also include diagonal platforms and make the player go up them (like in Terraria when you make stairs for example) but at the same time keep it so I don't get stuck and collide horizontally?
Also last thing is that my player can go into the platforms and since it's neither above or under but right in the middle she doesn't fall down. How can I make her not walk into them?
I'm also kind of slightly above the beginner level but no more. The collision code I have from old Shaun Spalding's platformer tutorials (because I can't make my own and I couldn't find newer ones that include slopes).
Code:
///colliding with stuff
//horizontal collisions
var hcollide;
hcollide = instance_place(x+hspd, y, obj_par_collision);
if (hcollide !=noone) {
if (hcollide.collision ==1) {
yplus = 0;
//the number in brackets for abs indicated how many pixels high a slope can be
while (place_meeting(x+hspd, y-yplus, obj_par_collision) && yplus<= abs(1*hspd)) {
yplus += 1;
}
if (place_meeting(x+hspd, y-yplus, obj_par_collision)) {
while (!place_meeting(x+sign(hspd), y, obj_par_collision)) {
x += sign(hspd);
}
hspd = 0;
} else {
y -= yplus;
}
}
}
//move horizontally
x += hspd;
//vertical collisions
var vcollide;
vcollide = instance_place(x, y+vspd, obj_par_collision);
if (vcollide != noone) {
if (vcollide.collision == 1) {
while (!place_meeting(x, y+sign(vspd), obj_par_collision)) {
y += sign(vspd);
}
vspd = 0;
mground = 1;
} //platform collisions
if ((vcollide.collision ==2) && sign(vspd) == 1) {
if (!place_meeting(x, y, obj_par_collision)) {
while (!place_meeting(x, y+sign(vspd), obj_par_collision)) {
y+=1;
}
vspd = 0;
mground = 1;
}
if (place_meeting(x, y, obj_par_collision) || (obj_player.dkey)) {
with obj_player {
scr_gravity();
mground = 0;
}
}
}
} else {
mground = 0;
}
//move vertically
y += vspd;
I believe the issue is with this piece of code in horizontal collisions:
Code:
if (hcollide.collision ==1) {
yplus = 0;
//the number in brackets for abs indicated how many pixels high a slope can be
while (place_meeting(x+hspd, y-yplus, obj_par_collision) && yplus<= abs(1*hspd)) {
yplus += 1;
}
Also last thing is that my player can go into the platforms and since it's neither above or under but right in the middle she doesn't fall down. How can I make her not walk into them?