Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Collision with Tilemap Layer
#11
(04-17-2020, 05:08 AM)megamarc Wrote: Some general advices:
  • when the intention of a function is to return a true/false value, define it as bool and return an explicit expression that evaluates to bool. test_direction() and detect_collision_area() have unclear intention, they return the numeric type of the tile but are treated as boolean.
  • logic of test_direction() is wrong. Implement it in a way that returns true only when all calls to detect_collision_area() return false, any positive in detect_collision_area() must return false. In layman terms: only allow motion if all testpoints are not colliding.
  • test_direction() has another problem, it only tests the corners of the character that are 32 pixels away, but tile size is 16 pixels. There are holes inside the character. Collision points must not be farther than 16 pixels. Insert an extra collision point in between.
Not repeating layers is not supported in tilengine, they always repeat. The effect you want can be easily implemented creating a thick solid border of empty tiles around your main map, and doing bound checking when trying to move.

Be safe you too!

How can I make the checks for 16 pixels? I am a bit confused about that.
Other than that I changed the test_direction() code to this. (and also made the check for the tile type be a specific boolean check)
Code:
static bool test_direction(const fix_t dir, const fix_t fx, const fix_t fy){
switch(dir){
case 0: //CASE DOWN
return !detect_collision_area(city, fx, fy + 32) &&
!detect_collision_area(city, fx + 32, fy + 32);
break;
case 1: //CASE UP
return !detect_collision_area(city, fx, fy + 16) &&
!detect_collision_area(city, fx + 32, fy + 16);
break;
case 2: //CASE LEFT
return !detect_collision_area(city, fx, fy + 16) &&
!detect_collision_area(city, fx, fy + 32);
break;
case 3: //CASE RIGHT
return !detect_collision_area(city, fx + 32, fy + 16) &&
!detect_collision_area(city, fx + 32, fy + 32);
break;
}

return 0;
}
I wish you could just mov the obstacle from the destination.
Reply


Messages In This Thread
RE: Collision with Tilemap Layer - by megamarc - 04-11-2020, 04:37 PM
RE: Collision with Tilemap Layer - by megamarc - 04-13-2020, 02:59 PM
RE: Collision with Tilemap Layer - by megamarc - 04-14-2020, 03:36 AM
RE: Collision with Tilemap Layer - by megamarc - 04-14-2020, 02:45 PM
RE: Collision with Tilemap Layer - by megamarc - 04-17-2020, 05:08 AM
RE: Collision with Tilemap Layer - by Uneven_Prankster - 04-19-2020, 08:00 AM

Forum Jump:


Users browsing this thread: 3 Guest(s)