Marquitos3000
Member
Hi, I´m making a plataformer game and I have this script for the player step event:
and this script for the player end step event:
But I have 2 problems:
the first one is that where it says
if I write a bigger number than 2.5, my character stops like 1 pixel before it touches the wall, and if I write 2.5 my character trespass like 1 pixel the wall, I don´t know what to put so that it can stop exactly when it touches the block.
My second problem is that if my character is on the top of the block and I walk slowly to the corner of the block, it trespasses it a bit (basically a bit less than half of the player verticaly is inside of the block) and it doesn´t let me move unless I jump. It only happens with the left half of the player. What should I do to correct it? the origin is down at the center 1 pixel below the player and the collision mask is covering all the player, which is a rectangle for now.
GML:
var hor = keyboard_check(vk_right) - keyboard_check(vk_left);
if (hor != 0) {
if place_free (x + hor*2.5, y ){
x += hor * 4
}
image_xscale = hor
}
if (keyboard_check_pressed(vk_up) && collision_rectangle(x-8,y,x+8,y+1,object1,false,false)) {
vspeed = -8;
}
Code:
if (!collision_rectangle(x-8,y,x+8,y+1,object1,false,false)) {
gravity = 0.3;
}
if (vspeed > 0) {
var ground = collision_rectangle(x-8,y,x+8,y+vspeed,object1,false,false);
if (ground) {
y = ground.y;
vspeed = 0;
gravity = 0;
}
} else if (vspeed < 0) {
var ceiling = collision_rectangle(x-8,y-63,x+8,y-63+vspeed,object1,false,false);
if (ceiling) {
y = ceiling.y + ceiling.sprite_height + 63;
vspeed = 0;
}
}
the first one is that where it says
Code:
if (hor != 0) {
if place_free (x + hor*2.5, y ){
x += hor * 4
}
image_xscale = hor
}
My second problem is that if my character is on the top of the block and I walk slowly to the corner of the block, it trespasses it a bit (basically a bit less than half of the player verticaly is inside of the block) and it doesn´t let me move unless I jump. It only happens with the left half of the player. What should I do to correct it? the origin is down at the center 1 pixel below the player and the collision mask is covering all the player, which is a rectangle for now.