GML Blocks that keep horizontal jump momentum with castlevania-like jump?

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.

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;
I've been trying to rework the collision without success, can somebody give me a hand?
 
I think I see the problem maybe. Inside your jump code, you are checking for horizontal movement, you should move that outside to it's own block which just checka if it's in the air and if there is a block horizontally in the way. Does that make sense?
 
B

Batandy

Guest
I think I see the problem maybe. Inside your jump code, you are checking for horizontal movement, you should move that outside to it's own block which just checka if it's in the air and if there is a block horizontally in the way. Does that make sense?
I'm sorry, could you be more specific? You mean the whole block or just the jump part ? Because there I just check if the player is on the ground or not, the horizontal collision is checked with another if statement unrelated to the jump action.
 
So this part is only going to happen the instant you jump, so you need to have something like that in it's own separate if statement that checks while they are in the air.
Code:
if (key_left) || (key_right) hsp = move * walksp; else hsp = 0;
Sorry, I'm on my phone, so I can't check and write a proper example.
 

NeZvers

Member
I'm failing to understand what's there is different with jumping into a wall.
The only thing that could be is different - already full speed, no need to accelerate.
in that case maybe something like this:

Code:
//Collisions for when player walks into blocks
var _hspd = hspd; //substitution variable
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;
 
B

Batandy

Guest
I'm failing to understand what's there is different with jumping into a wall.
The only thing that could be is different - already full speed, no need to accelerate.
in that case maybe something like this:

Code:
//Collisions for when player walks into blocks
var _hspd = hspd; //substitution variable
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;
Yes, this did the trick, thank you!
I was sorta thinking about a solution like that, but didn't exactly know how to implement it due to my very limited knowledge, so thank you very much!
 

TheouAegis

Member
if you're trying to simulate Castlevania mechanics, keep in mind that the bounding box did not go past the shoulders when moving horizontally. Simon and Trevor can jump through walls.

Also yeah, they didn't use pixel-perfect collisions in those old games, so hspeed was never altered upon collision.
 
Last edited:
B

Batandy

Guest
Yeah, i'm trying to make a game which plays similiarly to the Castlevania games, but it's not a fangame, this allows me to take multiple gameplay elements from the whole serie (SCIV's angled whip attacks for example).
Since I don't know a lot of GM coding yet, i'm taking small steps by trying to imitate CV1 first and then slowly add features from the modern iterations (and even my own)
 
Top