Okay, so I fixed both problems. I fixed the first script so it works with every size of sprite/mask, and I added a collision with obj_solid script. First script:
Using gml Syntax Highlighting
//If you didnt mark 'Treat uninitialized variables as value 0', add this code to your create event:
//myfriction = 0;
//scrPlatformMovement(friction, max move speed, jump key, jump speed, gravity speed, max gravity speed)
//example how to use it:
// scrPlatformMovement(0.5, 3, ord('Z'), 8, 0.5, 10)
//Can be used for basic platform games which don't include running
//Call this script in the Begin Step, Step or End Step event
//Checks if the jumping key is pressed
if keyboard_check_pressed(argument2)
{
//Lets the player jump
if (canjump == true)
{
//jumpspeed can be both positive and negative
vspeed = (abs(argument3) * -1);
canjump = false;
}
}
//Makes the player able to jump when on solid ground
if not place_free(x,y+1)
canjump = true;
//Adds gravity when in the air and removes gravity when on solid ground
if place_free(x,y+1)
gravity = argument4;
else if not place_free(x,y+1)
gravity = 0;
//Limits max gravity speed
if vspeed > argument5
vspeed = argument5;
//Adds friction
if (myfriction > 0 && place_free(x+myfriction+1,y)) or (myfriction < 0 && place_free(x-myfriction-1,y))
x += myfriction;
//Right
if keyboard_check(vk_right) && not keyboard_check(vk_left) && place_free(x+10,y)
{
myfriction += argument0
}
//Left
if keyboard_check(vk_left) && not keyboard_check(vk_right) && place_free(x-10,y)
{
myfriction -= argument0
}
//Slows player down when neither left or right is hold
if not keyboard_check(vk_left) && not keyboard_check(vk_right)
{
if myfriction > 0 then myfriction -= argument0
if myfriction < 0 then myfriction += argument0
}
//Slows player down when both left or right is hold
if keyboard_check(vk_left) && keyboard_check(vk_right)
{
if myfriction > 0 then myfriction -= argument0
if myfriction < 0 then myfriction += argument0
}
//Stops at max friction speed
if myfriction > argument1 then myfriction = argument1;
if myfriction < (argument1*-1) then myfriction = (argument1*-1);
Collision with obj_solid (be sure the object is solid and you're using the collision with obj_solid event to put this script in): Using gml Syntax Highlighting //scrSolidCollision()
move_contact_solid(270,12)
vspeed = 0 ^Small script, IK, but it works fine. BTW Drag, if you decide to add this, you can just add it in Scripts as scrPlatformMovement and refer to this post through a link, so people will know they need the solid code too.
Okay, so I fixed both problems. I fixed the first script so it works with every size of sprite/mask, and I added a collision with obj_solid script.
First script:
[syntax=gml]//If you didnt mark 'Treat uninitialized variables as value 0', add this code to your create event:
//myfriction = 0;
//scrPlatformMovement(friction, max move speed, jump key, jump speed, gravity speed, max gravity speed)
//example how to use it:
// scrPlatformMovement(0.5, 3, ord('Z'), 8, 0.5, 10)
//Can be used for basic platform games which don't include running
//Call this script in the Begin Step, Step or End Step event
//Checks if the jumping key is pressed
if keyboard_check_pressed(argument2)
{
//Lets the player jump
if (canjump == true)
{
//jumpspeed can be both positive and negative
vspeed = (abs(argument3) * -1);
canjump = false;
}
}
//Makes the player able to jump when on solid ground
if not place_free(x,y+1)
canjump = true;
//Adds gravity when in the air and removes gravity when on solid ground
if place_free(x,y+1)
gravity = argument4;
else if not place_free(x,y+1)
gravity = 0;
//Limits max gravity speed
if vspeed > argument5
vspeed = argument5;
//Adds friction
if (myfriction > 0 && place_free(x+myfriction+1,y)) or (myfriction < 0 && place_free(x-myfriction-1,y))
x += myfriction;
//Right
if keyboard_check(vk_right) && not keyboard_check(vk_left) && place_free(x+10,y)
{
myfriction += argument0
}
//Left
if keyboard_check(vk_left) && not keyboard_check(vk_right) && place_free(x-10,y)
{
myfriction -= argument0
}
//Slows player down when neither left or right is hold
if not keyboard_check(vk_left) && not keyboard_check(vk_right)
{
if myfriction > 0 then myfriction -= argument0
if myfriction < 0 then myfriction += argument0
}
//Slows player down when both left or right is hold
if keyboard_check(vk_left) && keyboard_check(vk_right)
{
if myfriction > 0 then myfriction -= argument0
if myfriction < 0 then myfriction += argument0
}
//Stops at max friction speed
if myfriction > argument1 then myfriction = argument1;
if myfriction < (argument1*-1) then myfriction = (argument1*-1);[/syntax]
Collision with obj_solid (be sure the object is solid and you're using the collision with obj_solid event to put this script in):
[syntax=gml]//scrSolidCollision()
move_contact_solid(270,12)
vspeed = 0[/syntax]
^Small script, IK, but it works fine.
BTW Drag, if you decide to add this, you can just add it in Scripts as scrPlatformMovement and refer to this post through a link, so people will know they need the solid code too.
_________________
|