Jump to content
A 2021 backup has been restored. Forums are closed and work in progress. Join our Discord server for more updates! ×
SoaH City Message Board

Correct Rolling Physics (GAME MAKER)


Recommended Posts

I really need some help with some of the codes from Sonic Reborn!

This code:

// deacceleration on slopes.
        if (ground == true && relative_angle > 35 && relative_angle < 335)
        {
            if ( action == action_rolling )
            {
                // first check where the character is heading to
                if ( x_speed > 0 )  // the character is heading to the right
                {
                    if ( relative_angle < 180 ) 
                        // the character is going up a slope...
                        x_speed -=  sin(degtorad(relative_angle)) * roll_decc_factor_up;
                    else                
                        // the character is going down a slope
                        x_speed -=  sin(degtorad(relative_angle)) * roll_decc_factor_down;
                } else {            // the character is heading to the left
                    if ( relative_angle > 180 ) 
                        // the character is going up a slope...
                        x_speed -=  sin(degtorad(relative_angle)) * roll_decc_factor_up;
                    else                      
                        // the character is going down a slope
                        x_speed -=  sin(degtorad(relative_angle)) * roll_decc_factor_down;            
                }
            } else {
                x_speed -= sin(degtorad(relative_angle)) * slope_decc_factor;
            }
        }

This code is used to deaccelerate on Slopes,but do you maybe know any way to make him keep rolling down slopes like he is supposed to do? I can't figure that out : p

Link to comment
Share on other sites

Actually, this code should work good. With this code player will continuing rolling on steep slopes. Maybe you placed another code in End Step or after this code, and Game Maker reading that code as higher priority. Anyway, if you will not find good resolution, try to put this code in end of End Step Event.

    // Deceleration based on angle
    if ( action == action_rolling ) {
    if ( ((x_speed > 0) && (relative_angle < 180)) || ((x_speed < 0) && (relative_angle > 180)))
        x_speed -= sin(degtorad(relative_angle)) * roll_decc_factor_up;
    if ( ((x_speed < 0) && (relative_angle < 180)) || ((x_speed > 0) && (relative_angle > 180)))
        x_speed -= sin(degtorad(relative_angle)) * roll_decc_factor_down;
    }
Edited by thevaleev
Link to comment
Share on other sites

Well since I code differently this may not work for the engine and such but you could adapt it:

 

 
// Adding motion to rolling
 
// Apply Normal Friction
    if ((Angle = 0) || (Angle=180)) && (Ground == true)
    {
         Speed -= 0.1125*Direction
    }
        
    // Apply Momentum Physics
    if (Ground == true) {
    if Speed > 0 && (Angle > 225 && Angle < 360) { Speed += 0.145 }
    if Speed < 0 && (Angle > 0 && Angle < 135)   { Speed -= 0.145 }
        
    if Speed > 0 && (Angle > 0 && Angle < 135)  { Speed -= 0.145 }
    if Speed < 0 && (Angle > 225 && Angle < 360){ Speed += 0.145 }
    }
 
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...