How to create a set jump path?

R

RetroNuva10

Guest
How could I make a jump like Simon's from Castlevania (NES), to where you can't change your trajectory and instead go in a set path with an incremental velocity?

So something like this:
 
Last edited by a moderator:
D

Deanaro

Guest
Disable movement while jumping.
Horizontal speed should stay a constant throughout the jump (no forces acting on it) unless the object colides with a wall.
At the start of the jump give the verticle speed a negative value and every step afterward add gravity to that speed.

Basically play with the horizontal and verticle speed until you are happy with the result!
Also here are some equations you can use to help you with balancing.
For verticle :
acceleration = gravity
V1 (final velocity) = V0 (initial velocity) +a(acceleration)*t(time)

V1^2=V0^2 + 2*a*d (distance)

d = V0*t + 1/2*a*t^2

d = (V0 + V1)/2*t

With this you can calculate what height you jump gets to and how long the jump takes, at what velocity you hit the ground ect...
For example you can get the time at which you reach the highest point of the jump, when V1 = 0, and have the value t for that.
Then you can check the maximum jump height using a different equation... anyways this will be good for fine tuning the jump. If you need a better explanation google "kinematic equations"
 
R

RetroNuva10

Guest
Thanks for the great reply! I'm having trouble producing this behavior though. I understand all the logic behind it (until you begin talking about different equations). Could you possibly type up a code that could produce this? I'm using states, so when the player presses Spacebar, it switches states to the Jump state, and then once ground is touched, it moves back to the Move state.
 
D

Deanaro

Guest
Thanks for the great reply! I'm having trouble producing this behavior though. I understand all the logic behind it (until you begin talking about different equations). Could you possibly type up a code that could produce this? I'm using states, so when the player presses Spacebar, it switches states to the Jump state, and then once ground is touched, it moves back to the Move state.
In create event:
Code:
G = 0.2; //gravity, this is the acceleration of the jump (a)
In steps:
Code:
if place_meeting (x,y+1,obj_solid) // if grounded
{
if keyboard_check_pressed (vk_space)
{
   vspd = - 10; // vertical speed , this is the initial celocity (V0)
   //hspd = number, check the direction of the jump and give it a hspd value.
}
}
else
{
    vspd += G; //add gravity to vspd
}

// your collision and movement (x +=hspd; y +=vspd;) code here, make sure to adjust the vspd and hspd variables to be the same as the ones you are using.
 

TheouAegis

Member
Castlevania has a transitional jump state. You go from idle or walk state during which time you press the jump key, to the transitional jump state during which time you set vspeed and save the hspeed, then you go to the jump state which is just where you handle collision checks.

This is really one of the simplest jumping mechanics in gaming history. It shouldn't be this difficult for you. If you know how to jump, you know how to do Castlevania jumps. A Mega Man or Mario jump is actually harder.
 

Erik

Member
@TheouAegis is right. If you have finished states for idle, jumping, falling, attacking and so on you just need to set the players speeds (vertical and horizontal) and then switch to your jumping state. The jumping state could just be a copy of your normal moving state but
without any directional input. The speeds are set before switching to the jumping state and as long as you are in that state they don't change (except for gravity and collisions).
Just remove left/right inputs from the jumping state and you should be good. ;)

If you wan't help in getting started with the code you first need to post some code so that we get some context. :)
If you post your state scripts i could take a look at it.
 
Top