C
Cabra
Guest
Hello everyone. I'm having trouble to understand how collision detection works, I'm really beginner and not being the english my main leanguage, manuals doesn't help.
Well, with that said, I'm trying to emulate Super Mario World physics, for now I only have the horizontal movement partially done and it's working fine. The problem comes when I try to make de colision detection with a wall, I tried a lot of things but nothing worked. From my experience (maybe I'm wrong), I've seen that Game Maker doesn't handle very well decimals numbers, so I'm trying to convert those decimals numbers into integers to make it pixel-perfect.
So from my logic, I say for example: "If I collide with a wall from the left, set my horizontal speed to 0, move my player -1 pixel to that specific wall and also convert my X axis number into an integer". But I don't have idea how to take it to the practice, there's still a lot of things that I need to learn from GML so a help wouldn't hurt. Also, I leave you the code and a gif so you see better what I have done.
(Oh, I almost forgot, I'm using a version of Game Maker 8 that I took from my school because I don't really have the money to pay for the Studio 2 and I'm really beginner, I'm using this version because I want to expand my knowledge and after that buy Studio 2)
Create event:
Step event:
This is what I have:
Well, with that said, I'm trying to emulate Super Mario World physics, for now I only have the horizontal movement partially done and it's working fine. The problem comes when I try to make de colision detection with a wall, I tried a lot of things but nothing worked. From my experience (maybe I'm wrong), I've seen that Game Maker doesn't handle very well decimals numbers, so I'm trying to convert those decimals numbers into integers to make it pixel-perfect.
So from my logic, I say for example: "If I collide with a wall from the left, set my horizontal speed to 0, move my player -1 pixel to that specific wall and also convert my X axis number into an integer". But I don't have idea how to take it to the practice, there's still a lot of things that I need to learn from GML so a help wouldn't hurt. Also, I leave you the code and a gif so you see better what I have done.
(Oh, I almost forgot, I'm using a version of Game Maker 8 that I took from my school because I don't really have the money to pay for the Studio 2 and I'm really beginner, I'm using this version because I want to expand my knowledge and after that buy Studio 2)
Create event:
Code:
xsp = 0;
vsp = 0;
acc = 0.1;
maxSpeed = 1.7;
slide = 0;
Code:
//Variables
x += xsp;
y += vsp;
kcright = keyboard_check(vk_right);
kcleft = keyboard_check(vk_left);
slide = acc * 3;
//Sprites
if (xsp != 0) {
sprite_index = sp_marioRun;
image_speed = 0.15;
}
else {
sprite_index = sp_marioQuiet;
}
//Físicas horizontales
if (xsp > maxSpeed) || (xsp < (maxSpeed * -1)) || !(kcright || kcleft) {
xsp -= (sign (xsp) * acc);
}
//Derecha
if (kcright) {
image_xscale = 1;
if (xsp < 0) {
xsp += slide;
sprite_index = sp_marioSlide;
}
else {
xsp += acc;
}
}
//Izquierda
else if (kcleft) {
image_xscale = -1;
if (xsp > 0) {
xsp -= slide;
sprite_index = sp_marioSlide;
}
else {
xsp -= acc;
}
}