K
Klangsucht
Guest
Hello there, like many other newbies I am following the famous platformer tutorial from shaun spolding.
Everything works so far, but I try to understand (for a few hours now) why the player really "jumps" like a smooth jump on spacebar-press. From what my logic tells me, the object should get teleported 7 pixels + the gravity value, up and from then on fall down the gravity value every tick. But it's also "sliding up" as fast as it's coming down like the the gravity value is negative (every tick).
Here is the code from my "every tick" elevent:
and the values in the create-elevent:
It's hard to form that question great enough for you to understand, and my english is worse too, but I just don't get, why the jump is a real "jump" instead of a teleport, 7,3 pixels up (vsp + grv). I mean, the jump-press is just once in a tick, but the game "remembers" that jump-press and slides the player up, same as it comes down after that.. Why isn't the game teleporting the player 7,3 pixels up in the first tick of the second..
Everything works so far, but I try to understand (for a few hours now) why the player really "jumps" like a smooth jump on spacebar-press. From what my logic tells me, the object should get teleported 7 pixels + the gravity value, up and from then on fall down the gravity value every tick. But it's also "sliding up" as fast as it's coming down like the the gravity value is negative (every tick).
Here is the code from my "every tick" elevent:
GML:
key_left = keyboard_check(vk_left);
key_right = keyboard_check(vk_right);
key_jump = keyboard_check_pressed(vk_space);
var move = key_right - key_left;
hsp = move * walksp;
vsp = vsp + grv;
if (place_meeting(x, y + 1, obj_erde)) && (key_jump)
{
vsp = -7;
}
//horizontal Collision
if (place_meeting(x+hsp, y, obj_erde))
{
while(!place_meeting(x+sign(x + hsp), y, obj_erde))
{
x = x + sign(hsp);
}
hsp = 0;
}
x = x + hsp;
//Vertical Collision
if (place_meeting(x, y+vsp, obj_erde))
{
while(!place_meeting(x, y +sign(y + hsp), obj_erde))
{
y = y + sign(vsp);
}
vsp = 0;
}
y = y + vsp;
Code:
grv = 0.3;
hsp = 0;
vsp = 0;
walksp = 4;