B
Batandy
Guest
Hello, i'm quite new and started making my first project a few days ago.
I'm making a Castlevania-like platformer where the jump's aircontrol is locked
The problem is that in Castlevania, if you jump near a block, the player's momentum is kept and he'll just slide vertically until he reaches the top of the block and the horizontal movement continues:
Like this basically
While, in my platformer, if you jump near a block, you'll only jump vertically and will not "climb over" the block, since colliding with it sets the horizontal speed to zero.
I've been trying to rework the collision without success, can somebody give me a hand?
I'm making a Castlevania-like platformer where the jump's aircontrol is locked
The problem is that in Castlevania, if you jump near a block, the player's momentum is kept and he'll just slide vertically until he reaches the top of the block and the horizontal movement continues:
Like this basically
While, in my platformer, if you jump near a block, you'll only jump vertically and will not "climb over" the block, since colliding with it sets the horizontal speed to zero.
Code:
---CREATE---
/// Main character states
isair = false;
// General Variables
hsp = 0;
vsp = 0;
grv = 0.2;
walksp = 1;
---STEP---
key_left = keyboard_check(vk_left);
key_right = keyboard_check(vk_right);
key_jump = keyboard_check_pressed(ord("X"));
if (place_meeting(x,y+1,SolidBlock)) //can only move while on the ground
{
var move = key_right - key_left; // 1 - 1 / If you press both keys at once the player doesn't move because 1 - 1 = 0
hsp = move * walksp; //multiplies move value (1 or -1) with the walksp value
}
vsp = vsp + grv;
if (place_meeting(x,y+1,SolidBlock)) && (key_jump) //if the player is standing on a block and presses the jump key
{
vsp = -4; //move the player up in the air by this value
if (key_left) || (key_right) hsp = move * walksp; else hsp = 0;
}
//Collisions for when player walks into blocks
if (place_meeting(x + hsp, y, SolidBlock)) { //about to collide
while (!place_meeting(x + sign(hsp), y, SolidBlock)) { //loop if condition is not true
x += sign(hsp);
}
hsp = 0;
}
x += hsp;
//Collisions for when player falls into blocks
if (place_meeting(x, y + vsp, SolidBlock)) {
while (!place_meeting(x, y + sign(vsp), SolidBlock)) {
y += sign(vsp);
}
vsp = 0;
}
y += vsp;
if (vsp != 0) inair = true; else inair = false;