• 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!

My character model will animate based off of input, but will not actually move

W

whocky

Guest
The problem is solved when I enter in x += hspd and y += vspd, but that overrides my collision script. Help!

GET INPUT SCRIPT HERE:

/// @desc get_input()
rKey = max(keyboard_check(vk_right), keyboard_check(ord("D")), 0);
lKey = max(keyboard_check(vk_left), keyboard_check(ord("A")), 0);
dKey = max(keyboard_check(vk_down), keyboard_check(ord("S")), 0);
uKey = max(keyboard_check(vk_up), keyboard_check(ord("W")), 0);

xaxis = (rKey - lKey);
yaxis = (dKey - uKey);

MOVE STATE SCRIPT HERE:

/// move_state
//Get Direction
dir = point_direction(0, 0, xaxis, yaxis);

//Get Length
if (xaxis == 0) && (yaxis == 0) {
len = 0;
} else {
len = spd;
}

// Get the speed variables
hspd = lengthdir_x(len, dir);
vspd = lengthdir_y(len, dir);

PLAYER COLLISION SCRIPT HERE:

var _collision = false

//Horizontal Tiles
if(tilemap_get_at_pixel(collisionmap, x + hspd, y))
{
x -= x mod TILE_SIZE;
if (sign(hspd) == 1) x += TILE_SIZE - 1;
hspd = 0;
_collision = true;
}

//Vertical Tiles
if(tilemap_get_at_pixel(collisionmap, x, y + vspd))
{
y -= y mod TILE_SIZE;
if (sign(vspd) == 1) y += TILE_SIZE - 1;
vspd = 0;
_collision = true;
}

return _collision

PLAYER OBJECT CREATE EVENT:
/// @desc Initialize

collisionmap = layer_tilemap_get_id(layer_get_id("Collision"));

image_speed = 0;
hspd = 0;
vspd = 0;
spd = 2.5;
len = 0;
dir = 0;

state = move_state;

spriterun = spr_playerrun;
spriteidle = spr_player;
localframe = 0;

PLAYER OBJECT STEP EVENT:
/// @desc Every Step
get_input();
script_execute(state);

if (!instance_exists(obj_fade)) {
script_execute(state);
} else {
sprite_index = 0
}

//Update Sprite Index
var _oldsprite = sprite_index;
if (len !=0)
{
direction = dir
sprite_index = spriterun;
} else sprite_index =spriteidle;
if (_oldsprite != sprite_index) localframe = 0;

//Update Image Index
player_animate_sprite();
 
S

Slothagami

Guest
You're trying to move the player without changing it's x and y values, which control it's position.
You could try:
GML:
if collision_script() {
    x += hspd;
    y += vspd;
}
But I would recommend adding in the x+= hspd; y += vspd; bit and rewrite your collision code so that it sets the appropriate h or vspd to 0 when a collision happens
Hope this helps
 
W

whocky

Guest
Thank you! I'm trying to figure out to do to a better tileset collision script, and hopefully that'll be done today.

Appreciate the help!
 
Top