W
wizen
Guest
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.
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!
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.");
}