public bool Rebound(float rAng) { //returns true of a rebound occurs //called automatically in Stage.CollisionDetect(...) //returns false when no rebound occurs if (!fHelper.airborne) return false; SPoint nVec = new SPoint(Mathf.Cos(rAng-Mathf.PI/2), Mathf.Sin(rAng-Mathf.PI/2));//should be normalized already float two_n_dot_d = 2*(nVec.x*GetVel().x + nVec.y*GetVel().y); SPoint rVec = new SPoint(GetVel().x - two_n_dot_d*nVec.x, GetVel().y - two_n_dot_d*nVec.y); float rDotN = rVec.x*nVec.x + rVec.y+nVec.y ;//angle of reflection float b_r=0; float fVel = GetVelF ()-tu_vRoThresh;//speed in units if (fVel > 0) { //if player is moving faster than the 'roll' threshhold b_r = (GetVelF())/ (tu_vReThresh-tu_vRoThresh); //bounce angle between 1 and 0, to determine how shallow to bounce if(b_r>1.0f)//simple sanity checks b_r=1.0f; else if(b_r<0) b_r=0; } //now determine rVec. //interpolate between rVec (max reflection) //and sVec(sliding) SPoint sVec = new SPoint (); sVec.x = Mathf.Cos (rAng)*fVel; sVec.y = Mathf.Sin (rAng)*fVel; // if (GetVel ().x > 0) // sVec.x = sVec.x * -1;//for facing in opposite direction SPoint cVel=new SPoint();//to combine cVel.x = rVec.x*b_r+sVec.x*(1.0f-b_r); cVel.y = rVec.y*b_r+sVec.y*(1.0f-b_r); if (cVel.x < 0) cVel.x = cVel.x; cVel.x = cVel.x * tu_bncRat;//bounce ratio here cVel.y = cVel.y * tu_bncRat;//bounce ratio here //Check for a tech float stAng=0; if (gCont.LStickTapped()) { SPoint stInv = new SPoint(-gCont.lStick.x, -gCont.lStick.y); stAng = stInv.GetDir (); if(Mathf.Abs (stAng-nVec.GetDir())<(Mathf.PI/4) ){ cVel.x = cVel.x*0.1f; cVel.y = cVel.y*0.1f; } } //if(rDotN> stats.tumble.thresh){ if( (fVel>0)){ stats.motion.vel = new SPoint(cVel.x, cVel.y); //TurnCheck(GetVel().x); if((Mathf.Abs(rAng) < Mathf.PI/3)||(Mathf.Abs(rAng-Mathf.PI) < Mathf.PI/3)||(Mathf.Abs(rAng+Mathf.PI) < Mathf.PI/3) ){ //landing on a flat-ish ground if(!stats.tumble.tmr.IsReady()){ fHelper.Animate("Slam", false, 0); Land (rAng); float spd = Mathf.Sqrt(stats.motion.vel.SqDistFromOrigin()); }else return false;//just land }else if(!stats.tumble.tmr.IsReady()) fHelper.Animate("WallSlam", false, 0); else return false;//just land }else return false; stats.tumble.rbdCount++; return true; }