Legacy GM Image Angle on Slopes [Solved]

MaxLos

Member
Hihi,

I currently have my player object rotate whenever it's on a slope. Player rotates fine but I'm having trouble figuring out how to only rotate the player when their fully on the slope. Right now I have it set up to just draw the sprite at the right angle whenever it's colliding with a slope like so:
Code:
if (grounded)
{
    if place_meeting(x,y+1,obj_slope_right)  draw_angle = 45; 
    else if place_meeting(x,y+1,obj_slope_left) draw_angle = -45;
    else draw_angle = 0;
}
But that causes it to rotate the sprite if the collision mask even touches the slope by 1 pixel (gif below). I'm thinking I should do the collision check at the bottom center but i dunno how I would go about doing that
Any help would be appreciated thanks

 

CloseRange

Member
There are probably better smarter ways but off the top of my head you could add a check if NOT colliding with a flat wall.
Or if you want it to just be the bottom center like you said use collision_point instead. Because it's not being used for actual 2d collisions it will be fine to not have to include the sprite's mask.
Then you just have to simply calculate the bottom center of the sprite mask and you're good.
 
C

Catastrophe

Guest
Regarding checking the bottom center, you would use the bbox variables. Or be lazy and use sprite_width, although that may get random visual bugs later on.

Or set your origin to bottom enter if you're very early in development xD Making design choices to fix one bug is the best.
 

MaxLos

Member
There are probably better smarter ways but off the top of my head you could add a check if NOT colliding with a flat wall.
Or if you want it to just be the bottom center like you said use collision_point instead. Because it's not being used for actual 2d collisions it will be fine to not have to include the sprite's mask.
Then you just have to simply calculate the bottom center of the sprite mask and you're good.
Thank you, your first suggestion worked great! It was still rotating the sprite just a bit too early so I added multiple checks of varying distances
Code:
!(place_meeting(x-2,y+1,obj_floor)) and !(place_meeting(x-1,y+1,obj_floor)) and !(place_meeting(x,y+1,obj_floor)) and !(place_meeting(x+1,y+1,obj_floor))
Which brings me to my next question, is there a way I can make that shorter? Not really a big deal but just curious. I tried collision_line but it didn't work? Probably used it wrong
 

CloseRange

Member
well if you store that in a variable:
Code:
var fColl = !(place_meeting(x-2,y+1,obj_floor)) and !(place_meeting(x-1,y+1,obj_floor)) and !(place_meeting(x,y+1,obj_floor)) and !(place_meeting(x+1,y+1,obj_floor));
you can use the fColl as the check:
Code:
if(fColl) {

}
and if you want to make the fColl part less spaghetti use a loop:
Code:
var fColl = true;
for(var i=-2; i<=1; i++)
     fColl = fColl && !place_meeting(x-i, y+1, obj_floor);
This at least makes it easy to adjust how many checks you wish to do
it's possible collision line would work, if so you'd do something like this:
Code:
var fColl = collision_line(x-2, y+1, x+2, y+1, obj_wall);
well except place_meeting checks the whole bounding box so you'd actually need to use bbox_left and right so maybe:
Code:
var fColl = collision_line(bbox_left-2, bbox_bottom+1, bbox_right+2, bbox_bottom+1, obj_wall);
 

Morendral

Member
I don't think that you need to do this at all, for this kind of game at least. It's not natural for someone to rotate like that on terrain, you would simply stand straight up and down
 

MaxLos

Member
well if you store that in a variable:
Code:
var fColl = !(place_meeting(x-2,y+1,obj_floor)) and !(place_meeting(x-1,y+1,obj_floor)) and !(place_meeting(x,y+1,obj_floor)) and !(place_meeting(x+1,y+1,obj_floor));
you can use the fColl as the check:
Code:
if(fColl) {

}
and if you want to make the fColl part less spaghetti use a loop:
Code:
var fColl = true;
for(var i=-2; i<=1; i++)
     fColl = fColl && !place_meeting(x-i, y+1, obj_floor);
This at least makes it easy to adjust how many checks you wish to do
it's possible collision line would work, if so you'd do something like this:
Code:
var fColl = collision_line(x-2, y+1, x+2, y+1, obj_wall);
well except place_meeting checks the whole bounding box so you'd actually need to use bbox_left and right so maybe:
Code:
var fColl = collision_line(bbox_left-2, bbox_bottom+1, bbox_right+2, bbox_bottom+1, obj_wall);
Thank you :)

I don't think that you need to do this at all, for this kind of game at least. It's not natural for someone to rotate like that on terrain, you would simply stand straight up and down
I mean yeah, I guess it isn't natural but it looks weirder to not rotate it imo cause it kinda makes it look like hes standing on air air.PNG
 

Morendral

Member
Thank you :)



I mean yeah, I guess it isn't natural but it looks weirder to not rotate it imo cause it kinda makes it look like hes standing on air View attachment 27378
You could try moving the character so that he's centered on the slope, and not just on his leading edge. You could also have separate sprites for the feet or legs on the slope.

I guess what I'm saying is that for however wrong it looks in that picture you just put up, rotating it looks worse.
 
Top