Legacy GM (SOLVED) Help with a point and click sidescroller

K

KuluGary

Guest
Hello! I'm not very fluent with GM:S at the moment but I'm eager to learn. I have used other, more simple, game engines but I want the skills that come from knowing how to code things.

As such, I tried following some tutorials on how to do both Point and click moement (in all directions) and Sidescroller movement and trying to mesh up at the best of my abilities.

This is the movement engine I have atm. I made so I can move horizontally towards the direction clicked thanks to a cursor obj, but my problem now is that while I have vertical collisions, I can't seem to make horizontal collisions work.

Code:
///Get the players input
key_move = mouse_check_button(mb_left);

//React to inputs
move = key_move;
mouseDistance = point_distance(x,y, obj_mouseClick.x, y);
hsp = move_towards_point(obj_mouseClick.x,y,min(4, mouseDistance));
if (vsp < 10) vsp += grav;

if(place_meeting(x,y+1,obj_solid))
{
    vsp = 0
}

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

}
x += hsp;

// Vertical collision
if(place_meeting(x,y+vsp,obj_solid))
{
    while(!place_meeting(x,y+sign(vsp),obj_solid))
    {
        y += sign(vsp);
    }
    vsp = 0;
}
y += vsp;
I, again, am at a really novice level but any hints on how to solve this would be greatly appreciated.

Thanks in advance!
 

Yal

šŸ§ *penguin noises*
GMC Elder
hsp = move_towards_point(obj_mouseClick.x,y,min(4, mouseDistance));
This is your problem - move_towards_point() changes speed, but doesn't actually return the new momentum. You'd want to read the speed first, then reset it, so your own movement code won't clash with the built-in momentum.
Code:
move_towards_point(obj_mouseClick.x,y,min(4, mouseDistance));
hsp = hspeed; hspeed = 0;
vsp = vspeed; vspeed = 0;
 
K

KuluGary

Guest
Sorry for the delayed response!

I had to edit your code a bit but it solved my problem :)

Thanks a ton.
 
Top