hmmm I don't really know a formular for this but a way to emulate something like this is able with using vars for vertical and horizontal movement...
something like this for example:
NPC Code:
if(playerenters){
this.vx=1;
this.vy=-1;
timeout=.05;
}
if(timeout){
if(!onwall(x+(width/2)+this.vx+(.025*this.vx),y+height/2)){x+=this.vx;}
else {this.vx=this.vx*(-1);}
if(!onwall(x+(width/2),y+(height/2)+this.vy+(.025*this.vy))){y+=this.vy;}
else {this.vy=this.vy*(-1);}
timeout=.05;
}
it's like the pong ball