2017-12-24 15 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

이 문제는이 문제가 추가 상자 입자 가속기 계획에 계획 기본 입자 가속기를 제거 지형 대신 다음 추가 계획을 수행 한 후 해결 단결 상자 입자 가속기 –

+0

를 추가 한 후 해결 3- \t 대상에 상자 콜리더 추가 카메라 레이 캐스트 관련 문제 –

답변

-1
:

다음 스크린 샷과 스크립트를 확인하시기 바랍니다

이 문제는 화합 상자 콜러 더를 추가 한 후에 해결됩니다.

이 문제는 다음을 수행 한 후에 해결됩니다. 1 지형 대신 계획 추가 - 계획 기본 충돌 자 제거 3 계획에 상자 충돌자 추가 4 상자 충돌자 추가 목표는 카메라 레이 캐스트 관련 문제 -