Legacy GM Sprite 'stepping' into the wall... a bit... sometimes...

Y

Yoo

Guest
Hey, again with the platform game. So I've managed to work out the vertical collision for jumping, but the horizontal is a bit tricky. It works but sometimes object will step a bit into the wall and maybe even cause problem with jumping later... probably because of the vertical collision. Also when that happens (sometimes), I am able to stick my object sideways, while in the air into the wall... as long as I am holding the directional key. Maybe it also has something to do with sprites and masking, but I just wanted to check if maybe it's something with the code:

Movement code i used:

if keyboard_check(ord("D")) hspeed = 20;

if keyboard_check(ord("A")) hspeed = -20;

if (speed > 15) speed = 15;

friction = 6;

Collision code:

if(place_meeting(x+hspeed,y,Object_Wall))
{
while(!place_meeting(x+sign(hspeed),y,Object_Wall))
{ x += sign(hspeed); }
hspeed=0;
}

x += hspeed;

Thanx in advance.

EDIT: I get the feeling like the object gains in speed at some points, and just rams through the wall...
 
S

Snail Man

Guest
The problem probably lies in the fact that you're using hspeed as your variable, but you also have x += hspeed at the end of the code. I'd suggest either changing the variable to xspeed, or deleting the x += hspeed at the end of the code
 
L

leonfook29

Guest
Like what Snail Man said, you should probably choose either using hspeed and the original collision code(because the engine will do a x += hspeed somewhere in some point), or use a custom variable for speed/movement(the upside? you can do slowmo and a bunch of awesome stuff with it without having an in-engine stuff mess with what you trying to achieve).
Also you should probably combine the x += hspeed; with the if above, so they won't do both thing, like so:

Code:
if(place_meeting(x+hspeed,y,Object_Wall))
{
    while(!place_meeting(x+sign(hspeed),y,Object_Wall))
    { x += sign(hspeed); }
    hspeed=0;
}else{
    x += hspeed;
}
 
Y

Yoo

Guest
Removing x += hspeed; does the trick, though it slows thing a bit down but I up it with hspeed with keyboard_check. I am pretty new with all this, so I am mixing stuff from the web I that I find, and probably lot of the things are wrong.... But, hope to learn as I go...
 
S

Snail Man

Guest
No sweat, that's how we all learned :)
Btw, don't forget to set the topic prefix to 'solved'!
 
  • Like
Reactions: Yoo
Top