1. Hey! Guest! The 33rd GMC Jam will take place between May 23rd, 12:00 UTC (Friday noon) and May 27th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

Character dodgerolling code fixing

Discussion in 'Programming' started by JohnSebek, May 11, 2019.

  1. JohnSebek

    JohnSebek Member

    Joined:
    Apr 2, 2018
    Posts:
    20
    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
    }
    
     
  2. StormGamez

    StormGamez Member

    Joined:
    Jun 12, 2017
    Posts:
    30
    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: May 13, 2019
    JohnSebek likes this.
  3. JohnSebek

    JohnSebek Member

    Joined:
    Apr 2, 2018
    Posts:
    20
    It´s working! Thank you so much :)
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice