For those that are creating RPGs in game maker this script will help you out, it's easy to setup collisions and it makes mapping and creating games much faster.
The default tile size is 32X32, change it to any size if it's "too" large for you.
There's ALLOT of keyboard checks but they're necessary to stop irregular movement, you can add diagonal movement if you'd like which isn't hard but make sure you know the direction as "motion" set is used.
without further ado here's the script.
Create Event:
CODE
// RPG Maker VX Movement setup
dir_8 = true; // Allow diagonal movement, if this is not a feature you want set it to false
tile_x = 32;
tile_y = 32;
dir = "d";
movesteps = room_speed * 0.5;
moving = 0;
image_speed = 0.3;
place_snapped(tile_x,tile_y);
Step Event:
CODE
/*
RPG Movement by Rukiri
*/
if place_snapped(tile_x,tile_y)
{
if dir_8=false
{
// get the direction
if keyboard_check(vk_down) { dir="d"; }
else if keyboard_check(vk_left) { dir="l"; }
else if keyboard_check(vk_right) { dir="r"; }
else if keyboard_check(vk_up) { dir="u"; }
}
else
{
// 8 direction
if !moving
{
if keyboard_check(vk_down) { dir="d"; }
else if keyboard_check(vk_left) { dir="l"; }
else if keyboard_check(vk_right) { dir="r"; }
else if keyboard_check(vk_up) { dir="u"; }
}
if (keyboard_check(vk_up) && !keyboard_check(vk_left) && !keyboard_check(vk_right)) { dir = "u"; }
else if (keyboard_check(vk_right) && !keyboard_check(vk_down) && !keyboard_check(vk_up)) { dir = "r"; }
else if (keyboard_check(vk_down) && !keyboard_check(vk_left) && !keyboard_check(vk_right)) { dir = "d"; }
else if (keyboard_check(vk_left) && !keyboard_check(vk_down) && !keyboard_check(vk_up)) { dir = "l"; }
if (keyboard_check(vk_up) && keyboard_check(vk_left) && dir!="u" && dir!="l") { dir = "l"; }
else if (keyboard_check(vk_up) && keyboard_check(vk_right) && dir!="u" && dir!="r") { dir = "r"; }
else if (keyboard_check(vk_down) && keyboard_check(vk_left) && dir!="d" && dir!="l") { dir = "l"; }
else if (keyboard_check(vk_down) && keyboard_check(vk_right) && dir!="d" && dir!="r") { dir = "r"; }
}
// move/stop the character
if keyboard_check(vk_down) { moving=1; motion_set(270, tile_y / movesteps); }
if keyboard_check(vk_left) { moving=1; motion_set(180, tile_x / movesteps); }
if keyboard_check(vk_right) { moving=1; motion_set(0, tile_x / movesteps); }
if keyboard_check(vk_up) { moving=1; motion_set(90, tile_y / movesteps); }
if keyboard_check(vk_nokey) { moving=0; motion_set(0,0); }
// move diagonally
if dir_8=true
{
if keyboard_check(vk_down) && keyboard_check(vk_left)
{
motion_set(point_direction(0, 0, -tile_x, tile_y), point_distance(0, 0, tile_x, tile_y) / movesteps);
}
if keyboard_check(vk_down) && keyboard_check(vk_right)
{
motion_set(point_direction(0, 0, tile_x, tile_y), point_distance(0, 0, tile_x, tile_y) / movesteps);
}
if keyboard_check(vk_up) && keyboard_check(vk_left)
{
motion_set(point_direction(0, 0, -tile_x, -tile_y), point_distance(0, 0, tile_x, tile_y) / movesteps);
}
if keyboard_check(vk_up) && keyboard_check(vk_right)
{
motion_set(point_direction(0, 0, tile_x, -tile_y), point_distance(0, 0, tile_x, tile_y) / movesteps);
}
if keyboard_check(vk_down) && keyboard_check(vk_up) { moving=0; motion_set(0,0); }
if keyboard_check(vk_left) && keyboard_check(vk_right) { moving=0; motion_set(0,0); }
}
if dir_8=false
{
// stop ilregular movement ( if diagonal movement is needed this is the area to add it )
if keyboard_check(vk_down) && keyboard_check(vk_up) { moving=0; motion_set(0,0); }
if keyboard_check(vk_left) && keyboard_check(vk_right) { moving=0; motion_set(0,0); }
if keyboard_check(vk_left) && keyboard_check(vk_down) { moving=0; motion_set(0,0); }
if keyboard_check(vk_left) && keyboard_check(vk_up) { moving=0; motion_set(0,0); }
if keyboard_check(vk_right) && keyboard_check(vk_down) { moving=0; motion_set(0,0); }
if keyboard_check(vk_right) && keyboard_check(vk_up) { moving=0; motion_set(0,0); }
}
// check for collisions
// control the sprites. Since VX uses 2 walk frames (walk,stand,walk) it's easier to just switch back and forth
if moving = 1
{
if dir="d"
{
sprite_index = spr_player_d;
}
else if dir = "l"
{
sprite_index = spr_player_l;
}
else if dir = "r"
{
sprite_index = spr_player_r;
}
else if dir = "u"
{
sprite_index = spr_player_u;
}
}
else { image_index = 1; }
}
If you do not want diagonal movement in your game than change dir_8 to false.
tile_x and tile_y are the variables you want to edit if you want a higher or smaller grid.
movesteps is what you want to edit when you're changing the speed of your character, only change it if you're sprite is running.
Well have fun!
DOWNLOAD DEMO! 3.44MB (There's tilesets inserted for a future RMVX Demo)
RPG Maker VX Engine, Movement demo