falling through the floor

W

WARlord02145

Guest
hey guys since am very new to Gamemakers studios am obviously going to stumble uppon some problems , since other threads and youtube seem to only take my time i will post my problem here.

//get player input
key_right = keyboard_check (vk_right);
key_left = keyboard_check (vk_left);
key_jump = keyboard_check_pressed (vk_space);

//calculate movement
var move = key_right - key_left;

hsp = move * Walkspeed;

hsp = move * Walkspeed;

vsp = vsp + gravity;

if (place_meeting(x,y+1,object1)) && (key_jump)

//horizontal collision
if (place_meeting(x+hsp,y,object1))
{
while (!place_meeting(x+sign(hsp),y,object1))
{
x = x + sign(hsp);
}
hsp = 0
}

x = x + hsp;

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

y = y + vsp;


i hope you will guys see why am i falling through the floor , i need an anwser asap , bless from the PAPA WARlord
 

FrostyCat

Member
Given that your code comes from a YouTube tutorial, re-watching that tutorial is the best way to see what you've done wrong.

For starters, 10:22 tells you not to use the variable name gravity, throughout the video they didn't call the blocks object1, and 31:28 tells you there should be something after the check involving key_jump. Re-watch that video from 12:22, 21:32 and 29:44 to see what you're missing.

I can put up with people being new to GM, but I won't put up with people being inattentive with instructions they've been given. It's cheap and disrespectable to shirk work and intellectual responsibility off to strangers at the slightest hitch.
 

TheouAegis

Member
The variable gravity is a built-in variable in gamemaker. It automatically gets added to the variable vspeed, which automatically moves an instance up or down. so by using the built-in variable gravity and not some custom variable like grv or grav, you are not only increasing the value of vsp, but also the value of vspeed. when the instance collides with the ground, you are indeed setting vsp to 0 and stopping this movement - within your custom movement code - but since you used a built-in variable, your collision code does not affect built-in movement and so you keep falling down.
 
Top