Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Knox on Tue 17/09/2013 03:27:38

Title: Math for isometric collisions
Post by: Knox on Tue 17/09/2013 03:27:38
Zabnat's Taxi Demo:http://www.adventuregamestudio.co.uk/forums/index.php?topic=36546.msg479382#msg479382 (http://www.adventuregamestudio.co.uk/forums/index.php?topic=36546.msg479382#msg479382)
How would I convert the math for vertical/horizontal collisions (0°-90°) to isometric ones (30°/210° - 150°/330°)?

Code (ags) Select

if (wall_angles[regionID] == 90) // vertical wall
        {
          //Display("VERTICAL COLLISION");
          fPatrolVelocity_world.x = -fPatrolVelocity_world.x * fMax(fAbs(sin_drive), 0.2);
          fPatrolVelocity_world.y = fPatrolVelocity_world.y * fMax(fAbs(sin_drive), 0.2);
        }
        else if (wall_angles[regionID] == 0) // horizontal wall
        {
          //Display("HORIZONTAL COLLISION");
          fPatrolVelocity_world.x = fPatrolVelocity_world.x * fMax(fAbs(cos_drive), 0.2);
          fPatrolVelocity_world.y = -fPatrolVelocity_world.y * fMax(fAbs(cos_drive), 0.2);   
        }


(http://i41.tinypic.com/26425jr.png)

(Khris, if you read this), can I use one of the formulas you used to answer previous iso convertion questions, or is it more complicated than that? Sorry if Im being reduntant on the issue!)
Title: Re: Math for isometric collisions
Post by: Khris on Tue 17/09/2013 11:54:04
Hi,
I have to go now, but I'll quickly post the general idea:

Starting with the car's isometric movement vector,
-convert to top-down by multiplying y-component by sin(45°)/sin(30°) = sqrt(2) ~ 1.414
-rotate by 45° by multiplying with 2D rotation matrix *
-apply collision code
-rotate by -45° *
-convert back to iso by dividing y-component by 1.414

* optional if collision code uses 45° walls
Title: Re: Math for isometric collisions
Post by: Khris on Tue 17/09/2013 22:42:32
Ok, this took way longer and more pages of scribbling than it should have :D

Code (ags) Select
  float stretch_by = 1.41421356;
  float xx = car_speed_x, yy = car_speed_y * stretch_by;
  float d = 0.7; // dampening
  if (wall_angle == "/") {
    car_speed_x = ((xx+yy) + d*(yy-xx))/2.0;
    car_speed_y = ((xx+yy) + d*(xx-yy))/2.0;
  }
  else {  // angle: \
    car_speed_x = ((xx-yy) - d*(xx+yy))/2.0;
    car_speed_y = ((yy-xx) - d*(xx+yy))/2.0;
  }
  car_speed_y = car_speed_y / stretch_by;