Right now my game has a ball that you can hit and bounce around the room, The problem is that at certain angles, the ball doesn't bounce as you would expect. I've attached a diagram of what's happening, and here is my code:
if(place_meeting(x+hspeed,y,oWall)){
//while(!place_meeting(x+sign(hspeed),y,oWall)){
// x += sign(hspeed)
//}
hspeed *= -1;
hor_bounce = 1;
speed = max(speed*bounce_coefficient,2);
trigger_event(event_ball_bounce)
direct_hit = 0;
}
if(place_meeting(x+hspeed,y+vspeed,oWall)){
//while(!place_meeting(x+hspeed,y+sign(vspeed),oWall)){
// y += sign(vspeed)
//}
speed = max(speed*bounce_coefficient,2);
vspeed *= -1;
trigger_event(event_ball_bounce)
direct_hit = 0;
}
image_angle += speed*5;
last_speed = speed;```
I assume what's happening here is that there's a problem with the horizontal speed and vertical speed being reversed within the same frame, but I'm not exactly sure why that's happening. I've tried all sorts of fixes and permutations of this code, but they all seem to break in one way or another. Appreciate any help