3
我的碰撞代碼應該反轉x的速度並將其降低到三分之一,然後當玩家沒有按下「A」或「D」鍵時,速度應該慢慢降低到零,但是,一旦玩家碰撞速度只降低到0.25和0.70之間的一個小的十進制(或正或負基於先前的方向。)碰撞後玩家的速度永遠不會變爲零?
//Function to determine what to do with keys
function KeyHandler():void{
//A Key Handlers
if(aKeyPressed == true){
if(Math.abs(_vx) < MaxSpeed){
_vx += -6;
}
}
//Player _vx somehow won't hit zero!!!
else if(aKeyPressed == false){
if(_vx < 0){
_vx += 1;
}
}
//D Key Handlers
if(dKeyPressed == true){
if(Math.abs(_vx) < MaxSpeed){
_vx += 6;
}
}
else if(dKeyPressed == false){
if(_vx > 0){
_vx += -1;
}
}
//W Key Handlers
if(wKeyPressed == true){
if(Jumped == false){
_vy = -15;
Jumped = true;
}
}
else if(wKeyPressed == false){
}
}
//Code for Right Collision
if(RightCollision){
while(RightCollision){
Player.x -= 0.1;
RightCollision = false;
if(_boundaries.hitTestPoint((Player.x + (Player.width/2)), (Player.y - (Player.height/2)), true)){RightCollision = true;}
}
_vx *= -.33
}
//Code for Left Collision
if(LeftCollision){
while(LeftCollision){
Player.x += 0.1;
LeftCollision = false;
if(_boundaries.hitTestPoint((Player.x - (Player.width/2)), (Player.y - (Player.height/2)), true)){LeftCollision = true;}
}
_vx *= -.33
}
謝謝你,我覺得它是這樣的,但只是無法包裹我的頭。 – Cory