justin123 Posted January 29, 2012 Report Share Posted January 29, 2012 I having trouble with curved slopes. The player makes it half way but gets stuck in the middle of the curve. The physics my engine uses is a direct port of the revival engine. I only had to change the way loops work since the Angel Script language doesn't have a "repeat()" loop or "do{}until()" loop. but here's the physics function: sorry about the formating void Physics() { // X Movement x += cos(degtorad(angle)) * x_speed; y += sin(degtorad(angle)) * x_speed; while (CollisionLeft( x, y, angle, maskMid) && x_speed < 0) { x += cos(degtorad(angle)); y -= cos(degtorad(angle)); } while (CollisionRight( x, y, angle, maskMid) && x_speed > 0) { x -= cos(degtorad(angle)); y += cos(degtorad(angle)); } //Y Movement if (!ground) { y += y_speed; // move the player outside in case he has got stuck into the floor or the ceiling while (y_speed < 0 && CollisionTop( x, y, 0, maskMid ) == true ) { x -= sin(degtorad(angle)); y += cos(degtorad(angle)); //y += 1; } while (y_speed > 0 && CollisionBottom( x, y, 0, maskMid ) == true ) { x += sin(degtorad(angle)); y -= cos(degtorad(angle)); //y -= 1; } if (y_speed >= 0 && CollisionBottom( x, y, 0, maskBig ) == true) { if ( CollisionLeftLimiter(0.0f) && CollisionRightLimiter(0.0f) ) { ChangeAngle(GetAngle( x, y, 0 ), gravity_angle); } else { ChangeAngle(0, gravity_angle); } x_speed -= sin(degtorad(angle)) * y_speed; y_speed = 0; ground = true; } } while (CollisionLeft( x, y, angle, maskMid) && x_speed < 0) { x += cos(degtorad(angle)); y -= cos(degtorad(angle)); } while (CollisionRight( x, y, angle, maskMid) && x_speed > 0) { x -= cos(degtorad(angle)); y += cos(degtorad(angle)); } //Slopes if (ground == true) { if (CollisionMain( x, y ) ) { while(CollisionMain( x, y)) { x -= sin(degtorad(angle)); y -= cos(degtorad(angle)); } } if (CollisionSlope( x, y, angle, maskMid ) && !CollisionMain( x, y ) ) { while(!CollisionMain( x, y )) { x += sin(degtorad(angle)); y += cos(degtorad(angle)); } } } //Other //fall if there isn't enough speed if (angle > 80 && angle < 280 && ground == true && abs(x_speed) < 3) { y_speed = -sin(degtorad(angle))*x_speed; x_speed = cos(degtorad(angle))*x_speed; ground = false; } // fall off the ground if the edges aren't colliding if (ground == true && angle != 0 && (CollisionLeftLimiter(angle ) == false || CollisionRightLimiter(angle ) == false )) { y_speed = -sin(degtorad(angle))*x_speed; x_speed = cos(degtorad(angle))*x_speed; ground = false; } // get new angle if (ground == true && CollisionLeftLimiter(angle) && CollisionRightLimiter(angle)) { // Store the new angle angle_holder = GetAngle( x, y, angle ); // Check if difference is less than 45. If it is, linear interpolate the angle, so it results on smoother rotation. // Otherwise, set the new angle normally. Remember that linear interpolation formula is the next: // // final = a*t + b*(1-t); where t is the interpolation value, wich goes from 0 to 1 // // There's also a shorter and faster method, wich is the one we're going to use: // // final = a + (b-a)*t; if (abs(angle-angle_holder)<45) ChangeAngle(angle + (angle_holder-angle)*0.5, gravity_angle); else ChangeAngle(angle_holder, gravity_angle); } else { ChangeAngle(0, gravity_angle); } } For some reason I can get the player to get unstuck and traverse the curve if I first get stuck for a while and press the opposite arrow key (releasing the other). Then thinking that it will go in the opposite direction, instead it makes it through the other half of the curve. Does anyone have any ideas? Link to comment Share on other sites More sharing options...
justin123 Posted January 31, 2012 Author Report Share Posted January 31, 2012 The images wasn't showing in my first post but its fixed now. What seems to be happening is somewhere around angles like 45 or 315, sonic begins to move in the opposite direction. So eventually he gets stuck in the middle. I can't figure out what could be causing this. My math functions output the same values as Game Maker's and collision is pretty much the same (but slower). I even went as far as testing the Revival Engine in debug mode and my own engine side-by-side in a identical map. the speed variables seemed to react the same and angles looked the same up to the point where you get stuck. This driving me crazy!!! Link to comment Share on other sites More sharing options...
Falk Posted January 31, 2012 Report Share Posted January 31, 2012 If your engine follows the conventional Sonic methodology of having four modes/quadrants for physics calculations (http://info.sonicretro.org/SPG:Solid_Tiles#The_Four_Modes), it sounds 'left' and 'right' are flipped in the vertical modes for some reason. Link to comment Share on other sites More sharing options...
justin123 Posted January 31, 2012 Author Report Share Posted January 31, 2012 The position of the sensors are rotated based on sonic's angle, so that seems to eliminate the need switching mode, unless I missed something. Link to comment Share on other sites More sharing options...
justin123 Posted February 2, 2012 Author Report Share Posted February 2, 2012 // X Movement x += cos(degtorad(angle)) * x_speed; y += sin(degtorad(angle)) * x_speed; I made a mistake here. Should be y -= sin. *facepalm* Link to comment Share on other sites More sharing options...
Recommended Posts