GML [SOLVED]Gradual grid movement

R

RisingKane

Guest
Hi everyone.

I'm trying to make some movement/animation, but I'm having some trouble.
Let's say I have a 32x32 grid. What I'd like to achieve is to move the player object tile by tile (32 pixels each). I managed to do that by setting the player's speed to 32, but it moves instantly to the next tile. I'd like the player object to move gradually until he/she reaches the center of the next tile. It could be pixel by pixel, maybe more.
I'm not using external buttons to move the player (mouse, keyboard). I have four in-game buttons (UP, DOWN, LEFT, RIGHT). When they're clicked, the player moves accordingly to which button was clicked.

Thanks!
 

NicoDT

Member
I use that mechanic in my game, and I came up with a pretty similar code to the one in that video.

Code:
if (key_right) && (moving=false)
{
    if  (instance_position(x+32,y,obj_coll_parent)= noone) and (x+32 < room_width)          //checking for enemies, blocks, and even if the next tile is outside of view.
    {
        xx= x + 32
        yy= y
        hspeed = walk_speed;
        vspeed = 0;
        state = pstates.move
        direc = pdir.right
        moving = true
        image_index +=1
    }
    else
    {                                                                     //this is so it faces the direction selected (in case there's an obstacle that doesn't allow me to move)
        direc = pdir.right
        state = pstates.stand
    }
}
 
Top