S
SolariumScum
Guest
I'm trying to get my enemy sprite/objects to not fall off (for certain enemies) or to actually fall off (certain other enemies) the top of the tiles in my 2d Platformer... also when hitting a collision tile object (box's ect...) then just turn around reversing direction -- ALL WHILE KEEPING MY RANDOMIZED DIRECTIONAL HOROZONTAL MOVEMENT.
I'm completely new to coding, like 3 weeks, first game ever attempted. First post ever as well.
I used the tutorial for the Platformer in Game Maker 2 as base -- YOYO PLATFORMER LITE --
I got the randomized direction (sudo AI) for the enemies working but then seems to cancel out the tile edge detection the original game had - essentially letting the enemies continue to go horizontally off the tiles tops, continuing the randomness in direction, but not staying on top of the tiles and reversing to only stay on top (would be great to have gravity make OTHER enemies fall down to next tile top as well) ...additionally when hitting a tile collision (box collision tile) also reversing direction?
Hope someone can help has really stopped my progress on the basic enemy movement and essentially the foundation of the game.
I'm completely new to coding, like 3 weeks, first game ever attempted. First post ever as well.
I used the tutorial for the Platformer in Game Maker 2 as base -- YOYO PLATFORMER LITE --
I got the randomized direction (sudo AI) for the enemies working but then seems to cancel out the tile edge detection the original game had - essentially letting the enemies continue to go horizontally off the tiles tops, continuing the randomness in direction, but not staying on top of the tiles and reversing to only stay on top (would be great to have gravity make OTHER enemies fall down to next tile top as well) ...additionally when hitting a tile collision (box collision tile) also reversing direction?
Hope someone can help has really stopped my progress on the basic enemy movement and essentially the foundation of the game.
Code:
/// --ENEMY OBJECT CREATE EVENT--
// You can write your code in this editor
dir = choose(-1,1);
// direction the ghost will be moving in
spd = 0; // speed the ghost moves
g= 0.2; // ghosts gravity
vspd = 0; // vertical speed the ghost is moving in
hspd = 0; // horizontal speed the ghost is moving in
////////////////speed the ghost is moving in
sprite_index = walk_duck; // animation to play
// default speed of the animation
// default speed of the animation
///my random asnimation
healthduck = 4;
knockback = false;
alarm[2] = 60;
ranmov = irandom_range(8,16);
Code:
///--ENEMY OBJECT SCRIPT--
var xx,yy,c1,c2;
// temp var only for use in this script
dir = choose(-1,1);
dir = ranmov;
hspd = dir * spd; // find out how far the object has moved
x += hspd;
// apply the distance to the object
if (hspeed <= 0){
image_xscale = -1;}
// set the sprite to point the correct wayif (hspeed >= 0) {
if (hspeed >= 0){
image_xscale = 1;}
if(x < 0){ // the the enemy has moved off the edge of the screen
x = room_width; // wrap around to the other side of the screen
}
if(dir == -1){ // if moving left
image_index = walk_duck; // set the sprite to point the correct way
c1 = -1; // reset the collision tile checkers
c2 = -1;
c1 = tilemap_get_at_pixel(oGame.map, x, y); // check the left edge of the sprite
c2 = tilemap_get_at_pixel(oGame.map,x,y+sprite_height); // check below the left edge of the sprite, since ghosts dont like heights
if((c1 >= 1) || (c2 <= 0)){ // if there is something blocking the left or if there would be a fall to the left
x = (x&$ffffffc0)+sprite_width; // move the object to the edge of the tile
dir *= -1; // change the direction
}
}else if(dir == 1) // if moving right
{ // Otherwise, check collision to the right
image_index = walk_duck; // set the sprite to point the correct way
c1 = -1 // reset the collision tile checkers
c2 = -1;
c1 = tilemap_get_at_pixel(oGame.map,x+sprite_width,y); // check the right edge of the sprite
c2 = tilemap_get_at_pixel(oGame.map,x+sprite_width,y+sprite_height); // check below the right edge of the sprite, since ghosts dont like heights
if((c1 >= 1) || (c2 <= 0)){ // if there is something blocking the right or if there would be a fall to the right
x = (x&$ffffffc0); // move the object to the edge of the tile || $ffffffc0 rounds the position to the nearest 64
dir *= -1; // change the direction
}
}
Last edited by a moderator: