Problem with Deceleration

R

RetroNuva10

Guest
I have a player object whose state variable is set to a player_jump state whenever up is pressed (the state script, of course, is executed in a step event)

It starts out being a certain vspd (which is constantly being added to the Player's y position), but I want it to start to decelerate (as a jump does) and then become positive so he then speeds up back towards the ground (Castlevania-style. I'll worry about mid-air control later). However, it seems like the real number that is being added to the vspd is being... ignored? I've tried larger numbers, like 2, which simply makes the Player not move at all vertically (as expected), which leads me to believe it might be rounding for some reason or another.

Additionally, the spritesheet for jumping is 2 images: frame 1 is crouching (to prepare for the jump), and frame 2 is the mid-air jump frame that is intended to play until he hits the ground.

Code:
vspd = -2;

if (image_index == 1) an = true;

if (an)
{
    image_speed = 0;
    image_index = 1;
    vspd += 0.4;
    y += vspd;
}
Oh, I also created a dummy object that simply did this exact code in a step event with its own vspd variable, and it had the same problem. (Just to confirm that it wasn't some other script affecting the jump)
 
R

RetroNuva10

Guest
Oh... heh... dumb mistake. The first line was constantly setting vspd to -2. I must have been staring at the problem for too long. :p

Here's the fix:
Code:
if (image_index == 1)
{
    an = true;
}
if (an)
{
    image_speed = 0;
    image_index = 1;
    vspd += 0.04;
    y += vspd;
} else vspd = -5;
 
Top