GMS 2 AI Platformer movement - tile based collision / AI Movement issue



Afternoon all,

I have just added enemy movement and it works as far as the enemy moving backwards and forwards, changing direction when it hits a wall. I am trying to extend this to have the enemy stay on a platform when required but at the moment the furthest I have made it results in a jerky back and forth movement on the spot.

I have tried testing for when it is no longer on the ground, tried amending the values and moving where it triggers the check.

Relevant code:
//move vertically
y += _velocity[VECTOR2Y];

//vertical collisions
if _velocity[VECTOR2Y] >= 0 {

    var _bbox_half = (bbox_right - bbox_left)*.5;
    var _tileBottom = scTileCollideAtPoint(_tilemapID, [bbox_left, bbox_bottom-1], [bbox_right-1,bbox_bottom-1],  [bbox_left + _bbox_half, bbox_bottom-1]) //-1 on right and bottom due to sub pixel movement
    or scTileCollideAtPoint(_tilemapID2, [bbox_left, bbox_bottom-1], [bbox_right-1,bbox_bottom-1],  [bbox_left + _bbox_half, bbox_bottom-1]); //-1 on right and bottom due to sub pixel movement
    if _tileBottom {
        y = bbox_bottom & ~ (TILESIZE -1);
        y -= bbox_bottom - y;
        _velocity[@ VECTOR2Y] =0;
    //---handle staying on platform---
    //check if no collision and required to stay
    if stayOnPlatform && !_tileBottom{
        foundEndOfPlatform = true; //update flag for end of platform to setup redirect
        //check which side came from and move back
        if _velocity[VECTOR2X] < 0{
            //move back to the right
            x = bbox_right & ~ (TILESIZE -1);
            x -= bbox_right - x;
            _velocity[@ VECTOR2X] =0; //prevent moving forward
        }else if _velocity[VECTOR2X] > 0{
            //move back to the left
            x = bbox_left & ~ (TILESIZE -1);
            x += TILESIZE + x - bbox_left ;
            _velocity[@ VECTOR2X] =0; //prevent moving forward
///@description determine where colliding with tiles
///@param tilemapID
///@param point array

var _tilemapID = argument[0];
var _collisionFound = false;

//loop through points and check for tile
for (var i = 1; i < argument_count; i++) {
    var _point = argument[i];
    _collisionFound = _collisionFound || tilemap_get_at_pixel(_tilemapID,_point[VECTOR2X],_point[VECTOR2Y]);


//return result
return _coll
State shift, including direction change, is triggered predominantly by the velocity hitting 0.
The problem looks to be on the check of _tileBottom as it is returning false while sitting on a platform, for some reason.

Any help would be appreciated, I am flummoxed by this!


Happy to take suggestions on a better implementation if that is easier?
Last edited by a moderator:


Another hour of debugging and no further. Any advice would be a big help!


Thanks for the reply. I will try the +1 but the -1 works for normal movement collision (I use a very similar script for player movement).