2016-03-19 19 views
0

好的,這是我的問題,我有一個腳本,允許我鎖定並圍繞敵方目標。問題在於,如果我的角色在按下鎖定按鈕時正在移動,那麼角色將繼續按按鈕按下之前的任何方向移動,無論按下多少按鈕保存相反的方向。統一字符繼續鎖定敵人時移動

這不會發生在我靜止的時候,如果我的角色靜止不動,我按下鎖定按鈕一切正常。只有當我移動時。

我不知道這是否是足夠的信息,或者還有什麼有人可能需要更好地理解,但這裏是我的腳本:

if (GetComponent<DetectedEnemies>().locked)//checks bool to see if lockOn button was pressed 
{ 
    mainCam.SetActive(false);//turns off main cam 
    lockCam.SetActive(true);//turns on lockOn cam 

    movesetting.tarObject = GetComponent<DetectedEnemies>().Closest;//target object will be the closest enemy to player 

    this.transform.LookAt(movesetting.tarObject.transform.position);//player will look at the target object at all times 

    if (currXRot.x > maxXRot.x)//if the current x rot of this object exceeds the maxXRot it can go... 
     currXRot.x = maxXRot.x;//it gets reset 

    transform.Translate(Vector3.right * movesetting.speed * Time.deltaTime * turnInput);//orbits around the target object 
    transform.Translate(Vector3.forward * movesetting.speed * Time.deltaTime * forwardInput);//in control of moving towards and away from target 
} 

任何及所有幫助是非常appreaciated,預先感謝您。如果您需要更多信息或者如果有什麼不清楚的地方,請告訴我。

回答

0

嘗試創建第二個用於軌道速度的速度變量。然後,如果玩家被鎖定,則將第一速度變量設置爲0,並且當玩家未被鎖定時,將軌道速度變量設置爲0.類似這樣:(以5作爲示例)

if(GetComponent.<DetectedEnemies>().locked) { 

speed = 5; 
orbitSpeed = 5; 
} else { 

speed = 5; 
orbitSpeed = 0; 
}