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();
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();