2014-09-20 65 views
0

我當前的平臺遊戲項目存在的問題是角色在角色左側撞牆之前停下來,並在角色右側停止太晚。角色hitTest牆壁

CharacterLeftHitTest

CharacterRightHitTest

這裏是有關問題的腳本:

char.topBumping=false; 
char.bottomBumping=false; 
char.leftBumping=false; 
char.rightBumping=false; 

char.speed=0; 
char.maxSpeedConstant=10; 
char.minSpeedConstant=-10; 

char.xVel=0; 
char.yVel=0; 

stage.addEventListener(Event.ENTER_FRAME,EnterFrame); 
function EnterFrame(e:Event){ 


    //local points 
    top_left_point_local = new Point(char.top_left.x,char.top_left.y); 
    bottom_left_point_local = new Point(char.bottom_left.x,char.bottom_left.y); 

    top_right_point_local = new Point(char.top_right.x,char.top_right.y); 
    bottom_right_point_local = new Point(char.bottom_right.x,char.bottom_right.y); 

    //global points 
    top_left_point = new Point(char.localToGlobal(top_left_point_local).x,char.localToGlobal(top_left_point_local).y); 
    bottom_left_point = new Point(char.localToGlobal(bottom_left_point_local).x,char.localToGlobal(bottom_left_point_local).y); 

    top_right_point = new Point(char.localToGlobal(top_right_point_local).x,char.localToGlobal(top_right_point_local).y); 
    bottom_right_point = new Point(char.localToGlobal(bottom_right_point_local).x,char.localToGlobal(bottom_right_point_local).y); 


    if(ground.hitTestPoint(top_left_point.x,top_left_point.y,true)){ 
     char.leftBumping=true; 
    } 
    if(ground.hitTestPoint(bottom_left_point.x,bottom_left_point.y,true)){ 
     char.leftBumping=true; 
    } 


    if(!ground.hitTestPoint(top_left_point.x,top_left_point.y,true)&&!ground.hitTestPoint(bottom_left_point.x,bottom_left_point.y,true)){ 
     char.leftBumping=false; 
    } 


    if(ground.hitTestPoint(top_right_point.x,top_right_point.y,true)){ 
     char.rightBumping=true; 
    } 
    if(ground.hitTestPoint(bottom_right_point.x,bottom_right_point.y,true)){ 
     char.rightBumping=true; 
    } 
    if(!ground.hitTestPoint(top_right_point.x,top_right_point.y,true)&&!ground.hitTestPoint(bottom_right_point.x,bottom_right_point.y,true)){ 
     char.rightBumping=false; 
    } 

    if(char.rightBumping){ 
     if(char.xVel>0){ 
      char.xVel=0; 
      char.speed=0; 
     } 
    } 
    if(char.leftBumping){ 
     if(char.xVel<0){ 
      char.xVel=0; 
      char.speed=0; 
     } 
    } 


    char.x+=char.xVel; 
    char.y+=char.yVel; 

} 

有其他人遇到這個問題?任何幫助都感激不盡。

更新:

這是問題的心臟,由於某種原因,性格擊中左壁上出來真在這裏即使在人物靜止不動(左不被按下)。

enter image description here

+0

聽起來像一個問題,就是當人物接近物體時通過簡單地檢查角色的速度是什麼來切斷角色接近物體時應該做出多少動作。例如,如果它們的速度是5,並且距離物體4個像素,則只能讓玩家移動4個像素,以便與物體對齊。 – 2014-09-21 04:50:25

+0

我看到你說什麼狡猾的拉斯卡爾,但你會如何建議我履行這一點 – DrakeTruber 2014-09-21 20:19:33

回答

0

好,許多加重小時後我終於解決了這個問題。電影剪輯內部的方向決定了它的整體位置。我從來不知道這一點。我一直認爲電影剪輯的內部與電影剪輯中心的關係並不重要。獲得的教訓,始終將影片剪輯的內部置於MC的舞臺上以簡化事情。