C
Chris Livermore
Guest
hi Gamemakers,
Im having some real trouble with tile collision detection, I am using the Shaun Spalding Tile Collision tutorial and trying to addapt it for my own game (which is a little different from the game Shaun was working on).
Basically my players Direction is determined by the mouse's X and Y Co-ordinates.
This then feeds into the player Object and the speed of the player is determined by globle.thrust making it so that the player always moves forward in the direction it is facing.
the problem I think I may be having is while chekcing the bounding boxes, currently I am working out what bounding boxes to check by working out the angle at whcih the direction is facing 0-360 (note that i have worked this out as absolute as I was having issues with the direction going into - values when a full 360 had been achieved.
if anyone has any ideas from looking at my code that would be great!
FYI the collision tiles I am using are 64x64, the player objects sprite is also 64x64.
I am currently seeing the ship get stuck when travelling upwards, bad or no collision when travelling left, bad or no collision when travelling right and bad or no collision when travelling down....
Code:
speed = global.thrust;
var bbox_side;
var AbsoluteDirection = abs(direction);
if (AbsoluteDirection >= 0 && AbsoluteDirection <= 89.99999999)
{//Facing Right
bbox_side = bbox_right;
}else if (AbsoluteDirection >= 90 && AbsoluteDirection <= 179.9999999)
{//Facing Down
bbox_side = bbox_bottom;
}else if (AbsoluteDirection >= 180 && AbsoluteDirection <= 269.9999999)
{//Facing Left
bbox_side = bbox_left;
}else if (AbsoluteDirection >= 270 && AbsoluteDirection <= 359.9999999)
{//Facing Facing up
bbox_side = bbox_top;
}
if (tilemap_get_at_pixel(collisionTileMap, bbox_side+speed, bbox_top) != 0) || (tilemap_get_at_pixel(collisionTileMap, bbox_side+speed, bbox_bottom) != 0)
{
speed = 0;
global.thrust = 0;
if (AbsoluteDirection >= 0 && AbsoluteDirection <= 89.99999999)
{//Facing Right
x = x - (x mod 64) + 63 - (bbox_right - x);
}else if (AbsoluteDirection >= 90 && AbsoluteDirection <= 179.9999999)
{//Facing Down
y = y - (y mod 64) - 63 - (bbox_bottom - y);
}else if (AbsoluteDirection >= 180 && AbsoluteDirection <= 269.9999999)
{//Facing Left
x = x + (x mod 64) - 63 - (bbox_left - x);
}else if (AbsoluteDirection >= 270 && AbsoluteDirection <= 359.9999999)
{//Facing Facing up
y = y + (y mod 64) + 63 - (bbox_top - y);
}
}
thanks for taking the time to read this post, if you need any further information ill be happy to provide!