- Code: Select all
//right move//
if(keyr&&!keyl){
if(xvelocity<3)xvelocity+=.5;}
//left move//
if(keyl&&!keyr){
if(xvelocity>-3)xvelocity-=.5;}
//friction(slow down)
if((keyl&&keyr)||(!keyl&&!keyr))
xvelocity*=.9;
EDIT: Ah i kinda get max and min after messing with them and changed some of the code to
- Code: Select all
if(keyr)
{
xvelocity+=.5;
xvelocity=min(xvelocity,3);
}
if(keyl)
{
xvelocity-=.5;
xvelocity=max(xvelocity,-3);
}