• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Character dodgerolling code fixing

J

JohnSebek

Guest
Hi so, I have my character doing the dodge roll, but I have an issue. When he rolls he can go through the wall and get stuck.
CODE OF MOVEMENT AND ROLLING IN STEP EVENT
Code:
//Player Movement
hspeed = walkingSpeed * (keyboard_check(ord('D')) - keyboard_check(ord('A')));
vspeed = walkingSpeed * (keyboard_check(ord('S')) - keyboard_check(ord('W')));
//roll
if (keyboard_check_pressed(vk_space)){ rolltime = 20; } if (rolltime > 0) { rolltime -= 1; x += lengthdir_x(walkingSpeed, direction); y += lengthdir_y(walkingSpeed, direction); }
//Collisions
if hspeed!=0
if !place_free(x+hspeed,y)
{
    if hspeed>0 move_contact_solid(0,hspeed)
    if hspeed<0 move_contact_solid(180,-hspeed)
    hspeed=0
}

if vspeed!=0
if !place_free(x+hspeed,y+vspeed)
{
    if vspeed>0 move_contact_solid(270,vspeed)
    if vspeed<0 move_contact_solid(90,-vspeed)
    vspeed=0
}
 

StormGamez

Member
this is because your manually adding the roll distance onto the x and y coordinants, if you were to change the code as the following it should work

Code:
//Set lastdir to the last direction moved
if(hspeed != 0 or vspeed != 0) {
    lastdir = point_direction(x,y,x+hspeed,y+vspeed);
}

//roll
if (keyboard_check_pressed(vk_space)){ rolltime = 20; } if (rolltime > 0) { rolltime -= 1; hspeed = lengthdir_x(walkingSpeed, lastdir); vspeed = lengthdir_y(walkingSpeed, lastdir); }
i've also added a "lastdir" variable so you dont always roll to the right, if you want it to only roll to the right just disregard the piece of code other wise copy it and set the "lastdir" variable in the create event

I hope that this helped

-SG
 
Last edited:
J

JohnSebek

Guest
this is because your manually adding the roll distance onto the x and y coordinants, if you were to change the code as the following it should work

Code:
//Set lastdir to the last direction moved
if(hspeed != 0 or vspeed != 0) {
    lastdir = point_direction(x,y,x+hspeed,y+vspeed);
}

//roll
if (keyboard_check_pressed(vk_space)){ rolltime = 20; } if (rolltime > 0) { rolltime -= 1; hspeed = lengthdir_x(walkingSpeed, lastdir); vspeed = lengthdir_y(walkingSpeed, lastdir); }
i've also added a "lastdir" variable so you dont always roll to the right, if you want it to only roll to the right just disregard the piece of code other wise copy it and set the "lastdir" variable in the create event

I hope that this helped

-SG
It´s working! Thank you so much :)
 
Top