I have a nice collision script for you, BUT, there are two conditions when using it.
1º - The movement must be done using the speed variables.
2° - You CAN'T have "slopes" or irregular surfaces, but with rectangular solids, it works like a charm.
Well, to make the character move with the speed variables is pretty simple.
First you need to add
HSPEED and
VSPEED, just like you where doing with the X and Y variables, however this is your acceleration value, not total speed.
Now on the create, you must define a
FRICTION value, remember, this value must be lower than the Acceleration Value.
Last but not least, you need to limit the speed, so the character won't be like sanic huehuehue...
There's a lot of ways of doing that, you can use a if statement:
Code:
if speed>MAXIMUM_SPEED then speed=MAXIMUM_SPEED
or you can use a
clamp function
Code:
speed=clamp(speed,0,MAXIMUM_SPEED)
Now, the collision code, remember to make sure that the solid object is NOT marked as solid.
And on the player, you create a collision code with it.
And put this Code:
Code:
//Move to the previous position
x = xprevious;
y = yprevious;
//Slide
if not place_meeting(x+hspeed,y,other.object_index) //If there's nothing at his horizontal direction
{x += hspeed} //It moves him to the direction he's going
else {hspeed=0}; //If not, It set his HSPEED to 0
if not place_meeting(x,y+vspeed,other.object_index) //Same thing as before, but this time on Vertical
{y += vspeed}
else {vspeed=0};
If you have any questions, feel free to send me a PM or something like that. ;D