• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Windows my character won't jump

i am just new to programming and wanted to try and build a game following a tutorial.

but now my character won't jump for some reason and i don't know that reason, i already tried somethings but still no result.

i dont know what i am doing wrong. i hope someone could help me with my code.

here is my code:

=========================================================================
GML:
//Get Player Input
key_left = keyboard_check(ord("A"));
key_right = keyboard_check(ord("D"));
key_jump = keyboard_check_pressed(ord("vk_space")) or keyboard_check_pressed(ord("vk_up"));

//make floor solid for player
if (place_free(x,y+vspeed))
{
    // make gravity
    gravity = 0.5;
}
else // they will be on the ground
{
    // make gravity and speed 0
    gravity = 0;
    vspeed = 0;
    
}

//Calculate Movement
var move = key_right - key_left;

hspeed = move * walksp;

vspeed = vspeed + gravity;

if (place_meeting(x,y+1,objectWALLGROUND)) and (key_jump)
{
    vspeed = -7;
}

//Horizontal Collision
if(place_meeting(x+hspeed,y,objectWALLMETAL))
{
       while(!place_meeting(x+sign(hspeed),y,objectWALLMETAL))
             {
               x = x + sign(hspeed);
             }
  hspeed = 0;
}

x = x + hspeed;

//Vertical Collision
if (place_meeting(x,y+vspeed,objectWALLMETAL))
{
       while (!place_meeting(x,y+sign(vspeed),objectWALLMETAL))
             {
               y = y + sign(vspeed);
             }
    vspeed = 0;
}
if (place_meeting(x,y+vspeed,objectWALLGROUND))
 {
       while (!place_meeting(x,y+sign(vspeed),objectWALLGROUND))
             {
               y = y + sign(vspeed);
             }

         vspeed = 0;   
 }

y = y + vspeed;
===============================================================
 

cactushead

Member
you can't use vk inside ord

change to something like this
GML:
key_jump = keyboard_check_pressed(vk_space) or keyboard_check_pressed(vk_up);
 
well.. got another problem now.

for some reason my character now gets stuck in the walls and also wont walk when on the ground. cant find a solution yet ;/

GML:
//Get Player Input
key_left = keyboard_check(ord("A"));
key_right = keyboard_check(ord("D"));
key_jump = keyboard_check_pressed(vk_space) or keyboard_check_pressed(vk_up);

//make floor solid for player
if (place_free(x,y+vspeed))
{
    // make gravity
    gravity = 0.5;
}
else // they will be on the ground
{
    // make gravity and speed 0
    gravity = 0;
    vspeed = 0;
    
}

//Calculate Movement
var move = key_right - key_left;

hspeed = move * walksp;

vspeed = vspeed + gravity;

if (place_meeting(x,y+1,objectWALLMETAL)) and (key_jump)
{
    vspeed = -10;
}

//Horizontal Collision
if (place_meeting(x+hspeed,y,objectWALLMETAL))
{
                 while(!place_meeting(x+sign(hspeed),y,objectWALLMETAL))
                    {
                       x = x + sign(hspeed);
                    }
hspeed = 0;
}
x += hspeed;

//vertical collision
if (place_meeting(x,y+vspeed,objectWALLMETAL))
{
       while (!place_meeting(x,y+sign(vspeed),objectWALLMETAL))
             {
               y = y + sign(vspeed);
             }
    vspeed = 0;
}


y = y + vspeed;

//restart room
if keyboard_check_pressed (ord("R"))
{
room_restart();
}
 
Top