Hey everyone,
I've never used the movement outside of the analog stick before, so assigning it to the dpad is new to me, and the way my code is set up. My bet is that its to do with the lngth variable, but not sure how to fix it still. Been trying for a while and coming up short.
Here's the code, would appreciate all the help I can get, cheers.
By the way, how do I create a code block below? Thanks!
I've never used the movement outside of the analog stick before, so assigning it to the dpad is new to me, and the way my code is set up. My bet is that its to do with the lngth variable, but not sure how to fix it still. Been trying for a while and coming up short.
Here's the code, would appreciate all the help I can get, cheers.
By the way, how do I create a code block below? Thanks!
GML:
// create event
getInput(); // all the shortcuts to the controller and keyboard, such as keyRight instead of keyboard_check_right, and so on
look = 0;
spd = 3;
walkSpd = spd;
hSpd = 0;
vSpd = 0;
xAxis = 0;
yAxis = 0;
lngth = 0;
drctn = 0;
diagSpd = round(spd * (sqrt(2) / 2));
image_speed = 1;
stand = RIGHT;
face = RIGHT;
state = movement;
//step event
function movement()
{
getInput();
depth = -y;
if (xAxis or yAxis) >= gamepad_set_axis_deadzone(0, 0.27)
{
// get direction via analog
drctn = point_direction(0, 0, xAxis, yAxis);
// get the hspeed and vspeed
hSpd = lengthdir_x(lngth, drctn);
vSpd = lengthdir_y(lngth, drctn);
// move
x += hSpd;
y += vSpd;
// control the sprite
image_speed = sign(lngth) * 0.6;
if lngth == 0
{
image_speed = 0;
}
else
{
image_speed = 1;
}
// get the length
if xAxis == 0 and yAxis == 0
{
lngth = 0;
}
else
{
lngth = spd;
}
}
// dPad controls needs editing
if dPadDown { vspeed = spd; sprite_index = sprGreenRunDown; } // none of the sprites animate when using the dpad
if dPadUp { vspeed = -spd; sprite_index = sprGreenRunUp; }
if dPadRight { hspeed = spd; sprite_index = sprGreenRunRight; }
if dPadLeft { hspeed = -spd; sprite_index = sprGreenRunLeft; }
if dPadUp && dPadLeft { sprite_index = sprGreenRunUpLeft; }
if dPadUp && dPadRight { sprite_index = sprGreenRunUpRight; }
if dPadDown && dPadLeft { sprite_index = sprGreenRunDownLeft; }
if dPadDown && dPadRight { sprite_index = sprGreenRunDownRight; }
if !dPadUp && !dPadDown { vspeed = 0; }
if !dPadRight && !dPadLeft { hspeed = 0; }
if (vspeed != 0) && (hspeed != 0) { spd = diagSpd; }
else { spd = walkSpd; }
}
Last edited: