Rotating Rectangle Collision

Currently I am using a script to handle box collisions, however I an realizing I need my box collider to a rectangle, and to be rotatable, as to better simulate the movements of a vaguely oblong tank without things clipping into other things. Unfortunately, I think this would either involve having to calculate the rotation vector and add it into the acceleration or possibly use two colliders with linked velocities and I am wondering if there's a simpler solution that I am missing.

This is the current code I'm using:


GML:
collisionVeloX= cos(angleDir*2*pi/360)*velocity;
collisionVeloY= -sin(angleDir*2*pi/360)*velocity;

xVelo = velocity;
yVelo = velocity;

if(place_meeting(x + collisionVeloX, y, obj_ow_nopass)){
  while(!place_meeting(x+ collisionVeloX,y,obj_ow_nopass))
  {
    x+=collisionVeloX;
  }
  xVelo = 0;
}

if(place_meeting(x, y + collisionVeloY, obj_ow_nopass)){
  while(!place_meeting(x, y+collisionVeloY,obj_ow_nopass))
  {
    y+=collisionVeloY;
  }
  yVelo = 0;
}

x+=cos(angleDir*2*pi/360)*xVelo;
y+=-sin(angleDir*2*pi/360)*yVelo;

I think I would need to do something like:

GML:
point_direction(oldAngle.x,oldAngle.y,newAngle.x,newAngle.y);
and then add that in to the current acceleration for the collision check.

I'm open to any solutions though.
 
Not sure what your trying to do exactly, but there is an option for rotating masks. Where you set the mask to be precise, there is an option for rotated.
 

relic1882

Member
Am I missing something or is there a reason you can't set the collision mask on the tank to Manual, then Rectangle with rotation? That way you could specify the rectangle within your tank sprite you want to be the collision mask.
 
Doing some quick tests, when rotating, the rectangle will just phase through the block instead of colliding. I'm assuming changing image_angle also changes the collision_mask when using rectangle with rotation ?
 

MD_Wade

Member
Doing some quick tests, when rotating, the rectangle will just phase through the block instead of colliding. I'm assuming changing image_angle also changes the collision_mask when using rectangle with rotation ?
Changing image_angle will affect the bounding box if it's not precise, or the overall collision if it is. To avoid "phasing" through the blocks, I'd suggest having a separate mask and just changing the way the object is drawn, rather than rotating it with image_angle.
 
Changing image_angle will affect the bounding box if it's not precise, or the overall collision if it is. To avoid "phasing" through the blocks, I'd suggest having a separate mask and just changing the way the object is drawn, rather than rotating it with image_angle.
That would defeat the purpose of using a rotating rectangle collider though.
 
Top