virtual protected void BounceOffCollidable_Up(Collidable collidable) { // We WERE grounded? Do special Portal-2-bouncy-gel-like bounce! if (pfeetOnGround) { float yVel = Mathf.Abs(vel.x) * 1.4f; SetVel(new Vector2(vel.x, yVel)); } // We WEREN'T grounded before? Do normal bounce! else { // Find how fast we have to move upward to restore our previous highest height, and set our vel to that! float distToRestore = Mathf.Abs(MathMaxConsideringGravFlip(0, maxYSinceGround - pos.y)); distToRestore += ExtraBounceDistToRestore(); // Give us __ more height than we started with. float yVel = Mathf.Sqrt(2 * -Gravity().y *GravFlipDir *distToRestore) * GravFlipDir; // 0 = y^2 + 2*g*dist -> y = sqrt(2*g*dist) yVel *= 0.982f; // hacky fudge: we're getting too much height back. yVel = MathMaxConsideringGravFlip(0.2f, yVel); // have at LEAST this much bounce. (i.e. no teeeeny-tiny bouncing.) SetVel(new Vector2(vel.x, yVel)); } timeLastBounced = Time.time; // Inform the collidable!! if (collidable != null) { collidable.OnPlayerFeetBounceOnMe(this); } }