# Legacy GMRotating a collision line check [Solved]

A

#### Aero88

##### Guest
Hi, I am a long time GM user, but haven't been very active on the forums since they were re-made which is why I have such a low post count.

I am making a platform game where the player can walk on the walls and the ceiling (or around a circle). Because the player can rotate, down is not always down (ie. 270 degrees)

I need to check directly under the players feet to see if there is a collision with a ground object regardless of the angle of the ground he is walking on. If it were a stranded platform game I would use something like this for the check.

Code:
``````if collision_line(bbox_left,y+1,bbox_right,y+1,objPar_Solid,true,true)
{
On_Ground = 1;
}
else
{
On_Ground = 0;
}``````
But since my player can rotate (the direction of gravity can be anywhere from 0-360) I cannot just check the line directly below him all the time. I need to be able to rotate the coordinates of the collision line to check a line rotated to match the angle of the player.

The player mask is a rectangle (32x64) with the origin at (16,63) so I need to check a collision line directly below that rectangle regardless of its rotation about the origin.

Thank you in advance for your help! If I need to clarify anything please let me know. I can usually think my way through stuff like this, but I am getting a little stumped on this one.

#### sp202

##### Member
Use the lengthdir functions for the second pair of co-ordinates. I'm not sure if the bounding box co-ordinates change with rotation, if they don't, might require the lengthdir there too.

A

#### Aero88

##### Guest
I was thinking I would need to use those, or at least a combination of sin/cos functions. Still trying to piece together how exactly to do that.

Perhaps if I treat the ends of the line as if they are on a polar coordinate I can then use the length_dir functions based off of the origin. I'll play around with that idea for a bit and see if I can get it to work. Thanks.

edit:

Thanks for getting me thinking. I was able to solve it using the following code.
Code:
``````//  Check if the player is on the ground
var On_Ground, Width, R, Theta, Alpha, Beta, P1X, P2X, P1Y, P2Y;

//  Calculate width of the player and radius to the ends of the collision line
R = sqrt(sqr(1)+sqr(Width/2));

// Calculate collision line coordinates
Theta = darctan(1/(Width/2));
Alpha = Theta+(180+image_angle);
Beta = (360+image_angle)-Theta;
P1X = x+lengthdir_x(R,Alpha);
P1Y = y+lengthdir_y(R,Alpha);
P2X = x+lengthdir_x(R,Beta);
P2Y = y+lengthdir_y(R,Beta);

//  Check under the player
if collision_line(P1X,P1Y,P2X,P2Y,objPar_Solid,true,true)
{
On_Ground = 1;
}
else
{
On_Ground = 0;
}``````

Last edited by a moderator: