Math for isometric collisions

Started by Knox, Tue 17/09/2013 03:27:38

Previous topic - Next topic

Knox

Zabnat's Taxi Demo: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

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);   
        }	




(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!)
--All that is necessary for evil to triumph is for good men to do nothing.

Khris

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

Khris

Ok, this took way longer and more pages of scribbling than it should have :D

Code: ags
  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;

SMF spam blocked by CleanTalk