• Hey! Guest! The 37th GMC Jam will take place between May 28th, 12:00 UTC and June 1st, 12:00 UTC. Why not join in! Click here to find out more!

Character dodgerolling code fixing

JohnSebek

Member
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:

JohnSebek

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
It´s working! Thank you so much :)
 
Top