Bridgewiz1956
Member
I am an experienced programmer but completely new to GMS2, my issue is to do with collisions, I think.
Problem Description :
I am writing a platformer. At the moment I have 7 blocks, defined as block objects as per Shaun's platformer course.
They are set up as follows:
X A X
XXXXX
I also have a character at point A.
When I hit the left arrow key the character goes left as expected , hits the far left block and transports to the far right block, if I keep the left key depressed he then travels to the far left block and stops ie behaves as expected.
If I depress the right arrow key the character key goes to the far right block, stops as expected, if I then depress the left arrow key he goes to the far left block and stops!
As you can imagine this is doing my head in. I have "nicked" the code from Shaun Spalding's Complete Platformer course, as follows;
//
// Check for Keyboard input
//
key_left = keyboard_check(vk_left);
key_right = keyboard_check(vk_right);
key_jump = keyboard_check_pressed(vk_space);
//
// Calculate Movement
//
var move = key_right - key_left;
hsp = move * walksp;
vsp = vsp + grv;
var on_ground = place_meeting (x , y + 1 , Obj_tile_top);
//
// Check for jump
//
if ((on_ground) && (key_jump))
{
vsp = -7;
}
Any help greatly appericated !!
The character is a one frame sprite with Auto Collision mask.
//
// Check for horizontal collision
//
if place_meeting(x + hsp,y,Obj_tile_top)
{ // Collision Detected so approach slowly
while ( !place_meeting (x + sign(hsp),y,Obj_tile_top))
{
x = x + 1;
}
hsp = 0;
}
x = x + hsp;
//
// Check for vertical collision
//
if place_meeting(x , y + vsp , Obj_tile_top)
{ // Collision Detected so approach slowly
while ( !place_meeting (x , y + sign(vsp) , Obj_tile_top))
{
y = y + 1;
}
vsp = 0;
}
y = y + vsp;
Problem Description :
I am writing a platformer. At the moment I have 7 blocks, defined as block objects as per Shaun's platformer course.
They are set up as follows:
X A X
XXXXX
I also have a character at point A.
When I hit the left arrow key the character goes left as expected , hits the far left block and transports to the far right block, if I keep the left key depressed he then travels to the far left block and stops ie behaves as expected.
If I depress the right arrow key the character key goes to the far right block, stops as expected, if I then depress the left arrow key he goes to the far left block and stops!
As you can imagine this is doing my head in. I have "nicked" the code from Shaun Spalding's Complete Platformer course, as follows;
//
// Check for Keyboard input
//
key_left = keyboard_check(vk_left);
key_right = keyboard_check(vk_right);
key_jump = keyboard_check_pressed(vk_space);
//
// Calculate Movement
//
var move = key_right - key_left;
hsp = move * walksp;
vsp = vsp + grv;
var on_ground = place_meeting (x , y + 1 , Obj_tile_top);
//
// Check for jump
//
if ((on_ground) && (key_jump))
{
vsp = -7;
}
Any help greatly appericated !!
The character is a one frame sprite with Auto Collision mask.
//
// Check for horizontal collision
//
if place_meeting(x + hsp,y,Obj_tile_top)
{ // Collision Detected so approach slowly
while ( !place_meeting (x + sign(hsp),y,Obj_tile_top))
{
x = x + 1;
}
hsp = 0;
}
x = x + hsp;
//
// Check for vertical collision
//
if place_meeting(x , y + vsp , Obj_tile_top)
{ // Collision Detected so approach slowly
while ( !place_meeting (x , y + sign(vsp) , Obj_tile_top))
{
y = y + 1;
}
vsp = 0;
}
y = y + vsp;