Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1057248 Posts in 42946 Topics- by 34887 Members - Latest Member: ULFR

October 25, 2014, 09:27:16 AM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)Improper landing
Pages: [1]
Print
Author Topic: Improper landing  (Read 382 times)
Reggie02
Level 0
**


View Profile
« on: March 26, 2013, 09:51:25 PM »

I'm new to game maker and was trying to implement a decent jump for a 2d character. IT works fine but when the character drops a certain height, he stops like 6 inches (relative to real life) above the floor for a sec before going all the way down. plus my character floats down if I rapidly tap the up key. This is my jumping code:

if place_free(x,y+1){
    gravity=0.5;
}
else{
    gravity=0;
}

if(keyboard_check(vk_right)){
    //if place_free(x+5,y){
        x+=curr_speed;
        if(curr_speed < max_speed){
            curr_speed+=0.5;
        }
    //}
}

if(keyboard_check_released(vk_right)){
    curr_speed = 0;
}



if(keyboard_check(vk_left)){
    if place_free(x-5,y){
        x-=7;
    }
}


if(keyboard_check(vk_up)){
//can_jump variable is to make sure character cannot jump in mid air
    if (can_jump=1){
        vspeed=-7;
        can_jump=0
    }
}
if(keyboard_check_released(vk_up)){
    vspeed = 0;
}
« Last Edit: March 26, 2013, 11:15:27 PM by Reggie02 » Logged
Netsu
Level 10
*****



View Profile WWW
« Reply #1 on: March 26, 2013, 11:22:24 PM »


if(keyboard_check_released(vk_up)){
    vspeed = 0;
}


Your vertical speed seems to get reset every time you release the up button, this is probably why you float if you tap it rapidly. What were you trying to achieve with this piece of code?
Logged

Reggie02
Level 0
**


View Profile
« Reply #2 on: March 26, 2013, 11:41:56 PM »

was trying to achieve the "hold longer to jump higher" function. My bad.
Logged
Netsu
Level 10
*****



View Profile WWW
« Reply #3 on: March 27, 2013, 02:03:23 AM »

You should make a separate variable called something like 'is_up_pressed', you can set it to true when someone presses up and to false when someone releases it. Then apply upward force (vspeed=-7 or something) for as long as the up is pressed and you are in air but no longer than some maximum amount of time (a fraction of a second usually works). This should make you jump higher when holding the button longer.
Logged

George Michaels
Level 0
***


I like big butts and I can not lie


View Profile
« Reply #4 on: March 27, 2013, 03:28:27 AM »

The way I made you jump longer if you hold longer was to reduce the players upward momentum by half gravity if they were holding the jump button, otherwise apply gravity normally. Eventually (after twice the normal time) the upward movement would be reduced to either equal zero or turn into downward movement.
Logged

Yeah, that.
Zack Bell
Level 10
*****



View Profile WWW
« Reply #5 on: March 27, 2013, 08:16:28 AM »

Back in my GM days I would do something similar to:

Code:
var kJumpReleased;

kJumpReleased = keyboard_check_released(ord('Z'));

...

} else if (kJumpReleased && vspeed < 0) {
    vspeed *= (grav * 0.5);
}
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic