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


Forum Jump:


Users browsing this thread: 1 Guest(s)