Legacy GM character go through wall/blocks

Z

zogo

Guest
hey,
I am using game maker 1.4.1
when I play my character go through the wall, and the walls are solid

here is my coding for character movement:
key_right = keyboard_check(vk_right);
key_left = -keyboard_check(vk_left);
key_jump = keyboard_check_pressed(vk_up);
key_up = keyboard_check(vk_up)
key_down = keyboard_check(vk_down)
move = key_left + key_right;
hsp = move * movespeed;
if (vsp < 10) vsp += grav;
if (place_meeting(x,y+1,Owall))
{vsp = key_jump * -jumpspeed}

and this is the variable
hsp = 0;
vsp = 0;
grav = 0.3;
grounded = (hsp = 0 and vsp = 0);
jumpspeed = 5;
movespeed = 4;
facing = 0;
 

woods

Member
if (place_meeting(x,y+1,Owall))
{vsp = key_jump * -jumpspeed}

if the wall is 1 away from the player, jump that way....


doesnt look like you are making the player do anything with the wall if they dont jump
 

TheouAegis

Member
"solid" means nothing if you don't have a collision event. Once you add a collision event, you'll start seeing things happen. And then you'll regret using "solid", but that's an issue for another day.
 

woods

Member
something like this might help...

if (keyboard_check(vk_right)) && (!place_meeting(x+1,y,Owall)) // check if right arrowkey is pressed and Owall is NOT 1pix to the right
{
// code to make player move right
}

// this basically makes the Owall a barrier and NOT have to have it a solid
 
Z

zogo

Guest
something like this might help...

if (keyboard_check(vk_right)) && (!place_meeting(x+1,y,Owall)) // check if right arrowkey is pressed and Owall is NOT 1pix to the right
{
// code to make player move right
}

// this basically makes the Owall a barrier and NOT have to have it a solid
I am using the same object as a wall and ground,
when the character is on top of the ground/block it is ok but when there is a wall/block in front of it the character can go through it
 

Attachments

Last edited by a moderator:

woods

Member
3rd hit on google search "gamemaker studio sidescroller collision" in some random thread


For a while a was looking for a perfect platformer, and I found one.

Create event:

grav = 0.2; hsp = 0; vsp = 0; jumpSpeed = 4; moveSpeed = 2;

Step event:

// Get input kLeft = -keyboard_check(vk_left); kRight = keyboard_check(vk_right); kJump = keyboard_check_pressed(vk_up);

// Use input move = kLeft + kRight; hsp = move * moveSpeed; if (vsp < 10) { vsp += grav; };

if (place_meeting(x, y + 1, obj_wall)) { vsp = kJump * -jumpSpeed }

// H Collisions if (place_meeting(x + hsp, y, obj_wall)) { while (!place_meeting(x + sign(hsp), y, obj_wall)) { x += sign(hsp); } hsp = 0; } x += hsp;

// v Collisions if (place_meeting(x, y + vsp, obj_wall)) { while (!place_meeting(x, y + sign(vsp), obj_wall)) { y += sign(vsp); } vsp = 0; } y += vsp;

I forget who made it, but full credit to them.

EDIT: It's Shawn Spaldings and the image speed thing was from a different project.



===============
it looks pretty much the same as what you have in your original post... looks like you didnt add the last couple lines dealing with horizontal and vertical collision..

Code:
// H Collisions if (place_meeting(x + hsp, y, obj_wall)) { while (!place_meeting(x + sign(hsp), y, obj_wall)) { x += sign(hsp); } hsp = 0; } x += hsp;

// v Collisions if (place_meeting(x, y + vsp, obj_wall)) { while (!place_meeting(x, y + sign(vsp), obj_wall)) { y += sign(vsp); } vsp = 0; } y += vsp;
 
Z

zogo

Guest
3rd hit on google search "gamemaker studio sidescroller collision" in some random thread


For a while a was looking for a perfect platformer, and I found one.

Create event:

grav = 0.2; hsp = 0; vsp = 0; jumpSpeed = 4; moveSpeed = 2;

Step event:

// Get input kLeft = -keyboard_check(vk_left); kRight = keyboard_check(vk_right); kJump = keyboard_check_pressed(vk_up);

// Use input move = kLeft + kRight; hsp = move * moveSpeed; if (vsp < 10) { vsp += grav; };

if (place_meeting(x, y + 1, obj_wall)) { vsp = kJump * -jumpSpeed }

// H Collisions if (place_meeting(x + hsp, y, obj_wall)) { while (!place_meeting(x + sign(hsp), y, obj_wall)) { x += sign(hsp); } hsp = 0; } x += hsp;

// v Collisions if (place_meeting(x, y + vsp, obj_wall)) { while (!place_meeting(x, y + sign(vsp), obj_wall)) { y += sign(vsp); } vsp = 0; } y += vsp;

I forget who made it, but full credit to them.

EDIT: It's Shawn Spaldings and the image speed thing was from a different project.



===============
it looks pretty much the same as what you have in your original post... looks like you didnt add the last couple lines dealing with horizontal and vertical collision..

Code:
// H Collisions if (place_meeting(x + hsp, y, obj_wall)) { while (!place_meeting(x + sign(hsp), y, obj_wall)) { x += sign(hsp); } hsp = 0; } x += hsp;

// v Collisions if (place_meeting(x, y + vsp, obj_wall)) { while (!place_meeting(x, y + sign(vsp), obj_wall)) { y += sign(vsp); } vsp = 0; } y += vsp;
3rd hit on google search "gamemaker studio sidescroller collision" in some random thread


For a while a was looking for a perfect platformer, and I found one.

Create event:

grav = 0.2; hsp = 0; vsp = 0; jumpSpeed = 4; moveSpeed = 2;

Step event:

// Get input kLeft = -keyboard_check(vk_left); kRight = keyboard_check(vk_right); kJump = keyboard_check_pressed(vk_up);

// Use input move = kLeft + kRight; hsp = move * moveSpeed; if (vsp < 10) { vsp += grav; };

if (place_meeting(x, y + 1, obj_wall)) { vsp = kJump * -jumpSpeed }

// H Collisions if (place_meeting(x + hsp, y, obj_wall)) { while (!place_meeting(x + sign(hsp), y, obj_wall)) { x += sign(hsp); } hsp = 0; } x += hsp;

// v Collisions if (place_meeting(x, y + vsp, obj_wall)) { while (!place_meeting(x, y + sign(vsp), obj_wall)) { y += sign(vsp); } vsp = 0; } y += vsp;

I forget who made it, but full credit to them.

EDIT: It's Shawn Spaldings and the image speed thing was from a different project.



===============
it looks pretty much the same as what you have in your original post... looks like you didnt add the last couple lines dealing with horizontal and vertical collision..

Code:
// H Collisions if (place_meeting(x + hsp, y, obj_wall)) { while (!place_meeting(x + sign(hsp), y, obj_wall)) { x += sign(hsp); } hsp = 0; } x += hsp;

// v Collisions if (place_meeting(x, y + vsp, obj_wall)) { while (!place_meeting(x, y + sign(vsp), obj_wall)) { y += sign(vsp); } vsp = 0; } y += vsp;
Thank you, the character doesn't go through wall any more but the movement is not smooth and it jumps higher
 

woods

Member
y += sign(vsp) // his... move Y position jump by 5
vs
vsp = key_jump * -jumpspeed // yours.. speed is 5


how does gravity effect these two differently?
it seems like his is a short teleport jump, if you will.. therefore it doesnt get affected by the gravity .... thinking outside the box here ;o)
 

TheouAegis

Member
y += sign(vsp) // his... move Y position jump by 5
vs
vsp = key_jump * -jumpspeed // yours.. speed is 5


how does gravity effect these two differently?
it seems like his is a short teleport jump, if you will.. therefore it doesnt get affected by the gravity .... thinking outside the box here ;o)
Those two lines are completely different in function. One will not work without the other. And both of the guys, including the OP, used both of those lines.
 

woods

Member
maybe it was a 3am thought.... but hahaha it took me about a day to wrap my head around the 2 h and v collision lines...

im curious as to why the movement and changed to choppy... since the only thing OP added was the2 collisions....??
 
Z

zogo

Guest
I found why it jumps higher and faster it was because I have got x +=hsp and y +=vsp twice

at the collisions
// H Collisions if (place_meeting(x + hsp, y, obj_wall)) { while (!place_meeting(x + sign(hsp), y, obj_wall)) { x += sign(hsp); } hsp = 0; } x += hsp;

// v Collisions if (place_meeting(x, y + vsp, obj_wall)) { while (!place_meeting(x, y + sign(vsp), obj_wall)) { y += sign(vsp); } vsp = 0; } y += vsp;

and at the very end of my code
x += hsp;
y += vsp;


I deleted the code at end and it is back to normal now also the character doesn't go through walls but sometimes it get stuck.
 
Top