2016-03-19 11 views
0

これは私の問題です。敵のターゲットをロックして軌道に乗せるスクリプトがあります。問題は、私のキャラクターがロックオンボタンを押したときに動いている場合、それ以上のボタン押下が反対方向に保存されているかどうかにかかわらず、ボタンが押される前にどんな方向にでもキャラクターが移動し続けることです。敵にロックされた状態でユニティキャラクターが動い続ける

これは私のキャラクターがまだ立っていて、すべてのボタンが効いているボタンを押しても、私が静止しているときは起こりません。私が動いている時だけです。

私は、これは十分な情報である場合、または誰かがよりよく理解する必要があるが、ここで私のスクリプトであるかもしれない他に何かわからない:、任意およびすべてのヘルプは大幅にappreaciatedさ

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 
} 

事前にお願いします。もっと情報が必要な場合、または何かが明確でない場合は、私に知らせてください。

答えて

0

周回速度に使用する2番目の速度変数を作成してみてください。次に、プレーヤーがロックされている場合、最初の速度変数を0に設定し、プレーヤーがロックされていないときには、軌道速度変数を0に設定します。

関連する問題