2017-12-24 13 views
-1

バーチャルジョイスティックには、カメラが地形や地面から見える問題を中心に、すべてのシーンを回転させるカメラ「軌道」を制御する責任があります。それをどうやって防ぐのですか?フリーカメラ-orbit VirtualJoystick

enter image description here

enter image description here

enter image description here

using UnityEngine; 
using System.Collections; 

public class FreeCamera : MonoBehaviour { 
    public Transform lookAt; 
    public VirtualJoystick camerajs; 
    private float distance = 200.0f; 
    private float currentx = 0.0f; 
    private float currenty = 0.0f; 
    private float sensitivityx = 1.0f; 
    private float sensitivityy = 1.0f; 
    private void Update() 
    { 
     currentx += camerajs.InputDirection.x * sensitivityx; 
     currenty += camerajs.InputDirection.z * sensitivityy; 
    } 
    private void LateUpdate() 
    { 
     Vector3 dir = new Vector3(0, 0, -distance); 
     Quaternion rotation = Quaternion.Euler(currenty, currentx, 0); 
     transform.position = lookAt.position + rotation * dir; 
     transform.LookAt(lookAt); 
    } 
} 

using UnityEngine; using System.Collections; using UnityEngine.UI; using UnityEngine.EventSystems; 

public class VirtualJoystick : MonoBehaviour,IDragHandler,IPointerUpHandler,IPointerDownHandler { 

    private Image bgImg; 
    private Image joystickImg; 
    public Vector3 InputDirection{ set; get;} 
    // Use this for initialization 
    void Start() { 
     bgImg = GetComponent<Image>(); 
     joystickImg = transform.GetChild (0).GetComponent<Image>(); 
     InputDirection = Vector3.zero; 

    } 

    // Update is called once per frame 
    //void Update() { 

    //} 
    public virtual void OnDrag(PointerEventData ped) 
    { 
     Vector2 pos = Vector2.zero; 
     if (RectTransformUtility.ScreenPointToLocalPointInRectangle 
      (bgImg.rectTransform, 
       ped.position, 
       ped.pressEventCamera, 
       out pos)) { 
      pos.x=(pos.x/bgImg.rectTransform.sizeDelta.x); 
      pos.y=(pos.y/bgImg.rectTransform.sizeDelta.y); 
      float x=(bgImg.rectTransform.pivot.x==1) ? pos.x*2+1 : pos.x*2-1; 
      float y=(bgImg.rectTransform.pivot.y==1) ? pos.y*2+1 : pos.y*2-1; 
      InputDirection=new Vector3(x,0,y); 
      InputDirection=(InputDirection.magnitude>1) ? InputDirection.normalized : InputDirection; 

      joystickImg.rectTransform.anchoredPosition= 
       new Vector3(InputDirection.x*(bgImg.rectTransform.sizeDelta.x/3),InputDirection.z*(bgImg.rectTransform.sizeDelta.y/3)); 
      Debug.Log(InputDirection); 
     } 

    } 
    public virtual void OnPointerDown(PointerEventData ped) 
    { 
     OnDrag (ped); 

    } 
    public virtual void OnPointerUp(PointerEventData ped) 
    { 


     //Here is the problem it just goes to zero so fast so my character also moves so fast...how can i make it so motth 
     InputDirection =Vector3.zero; 
     joystickImg.rectTransform.anchoredPosition =Vector3.zero; 
    } 
} 
+0

何か助け......? –

+0

この問題は、この問題が 、3- \t追加ボックスコライダー計画に計画・デフォルト・コライダーを削除地形 2 - \tするのではなく、次の の1- \t追加計画を実行した後に解決された統一ボックスコライダー –

+0

を追加した後に解決され 、4- \tターゲットにボックスコライダーを追加する カメラレイキャストに関連する問題 –

答えて

-1

次のスクリーンショットやスクリプトを確認してください

この問題は、ユニティボックスのコライダーを追加した後に解決されます

この問題は、以下を実行した後に解決されます:地形の代わりにプランを追加する2-プランのデフォルトコライダーを削除する3-プランにボックスコライダーを追加する4-ボックスコライダーを追加するカメラのレイキャストに関連する問題をターゲットに -

関連する問題