GML Problem with HeartBeast's Tile Collision System

wizen

Member
Hi,

I've been having a small issue with (I think) HeartBeast's tile collision system in a 2D platformer environment, and I think I've found the place where it consistently fails, but I'd like some confirmation from someone a little more experienced than I am.

The jist of it is that I've written a script called scrPatrolNoDrop (which has the enemy patrol on a platform, reversing x-velocity if it hits a wall or runs out of platform. Pretty simple, and it works perfectly) and then tried to adapt the script to scrPatrolJumpOver (which would have the enemy jump over any obstacles in its way) with no success. Here's the script.

Code:
// Depending on facing, return the appropriate bounding box corners.
var frontTop;
var frontMid;
var frontBottom;
var backBottom;
var midY = (bbox_bottom-bbox_top)/2;
var midX = (bbox_right-bbox_left)/2;
var midBottom = [midX,bbox_bottom+1];
    
if (image_xscale == 1) {
    frontTop = [bbox_right+1,bbox_top];
    frontMid = [bbox_right+1,midY];
    frontBottom = [bbox_right+1,bbox_bottom+1];
    backBottom = [bbox_left-1,bbox_bottom+1];
} else {
    frontTop = [bbox_left-1,bbox_top];
    frontMid = [bbox_left-1,midY];
    frontBottom = [bbox_left-1,bbox_bottom+1];
    backBottom = [bbox_right+1,bbox_bottom+1];
}

// If the place beside you isn't free, but you can jump up there, jump.
if (scrTileCollideAtPoints(collision_tile_map_id,frontMid)){
    velocity_[1] += -7;
    trace("Tried to jump!");
}

// If the place beside you isn't free, turn around.
if (scrGrounded() && scrTileCollideAtPoints(collision_tile_map_id,frontMid)){
    velocity_[0] = velocity_[0] * -1;
    image_xscale = sign(velocity_[0]);
    trace("Turning around 'cuz bumping face.");
}
// If the place below and ahead of you is free, turn around.
if (scrGrounded() && !scrTileCollideAtPoints(collision_tile_map_id,frontBottom)){
    velocity_[0] = velocity_[0] * -1;
    image_xscale = sign(velocity_[0]);
    trace("Turning around 'cuz not suicidal.");
}
It works perfectly when the enemy's frontTop collides with a wall, but when only frontMid hits, it doesn't turn around. Is there a way for me to recognize when the enemy's frontMid hits an obstacle? I'd appreciate any suggestions. Thanks!
 

TheouAegis

Member
I dont see a frontTop check there.

You may need some else calls or nest conditions.

if collision at frontTop
{ turn around }
else
if collision at frontMid
{ jump }
else
if no collision at frontBottom
{
if no collision at aheadBottom
{ turn around }
else
{ jump }
}
 

wizen

Member
I left frontTop off because I was going to do a nested if with it in there, but then I noticed that all direction reversing action was being stopped and frontMid wasn't being recognized as a valid collision point, and I guess left it out while troubleshooting. Doesn't matter, anyway. They're not turning around or jumping if frontMid is the only point of collision.
 

TheouAegis

Member
Oh. I see what you did wrong.

bbox_bottom-bbox_top should be bbox_bottom+bbox_top.

Halfway-points are (A+B)/2, not (A-B)/2
 
Top