- Home /
 
               Question by 
               panim0_unity · Oct 03, 2019 at 01:37 PM · 
                c#camerarotationposition3rd person controller  
              
 
              How to move camera up and down
This is the script ı use on an image to use as my touch area
 public class FixedTouchField : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
 {
     [HideInInspector]
     public Vector2 TouchDist;
     [HideInInspector]
     public Vector2 PointerOld;
     [HideInInspector]
     protected int PointerId;
     [HideInInspector]
     public bool Pressed;
 
     // Use this for initialization
     void Start()
     {
 
     }
 
     // Update is called once per frame
     void Update()
     {
         if (Pressed)
         {
             if (PointerId >= 0 && PointerId < Input.touches.Length)
             {
                 TouchDist = Input.touches[PointerId].position - PointerOld;
                 PointerOld = Input.touches[PointerId].position;
             }
             else
             {
                 TouchDist = new Vector2(Input.mousePosition.x, Input.mousePosition.y) - PointerOld;
                 PointerOld = Input.mousePosition;
             }
         }
         else
         {
             TouchDist = new Vector2();
         }
     }
 
     public void OnPointerDown(PointerEventData eventData)
     {
         Pressed = true;
         PointerId = eventData.pointerId;
         PointerOld = eventData.position;
     }
 
 
     public void OnPointerUp(PointerEventData eventData)
     {
         Pressed = false;
     }
 
 }
And here my script attached to my player
    public float kameraX;
     public float kameraY;
     public float kameraZ;
 
     public FixedJoystick LeftJoystick;
     public FixedButton Button;
     public FixedTouchField TouchField;
 
 
     protected LionActions actions;
     protected LionPlayerControls lionPlayerControls;
     protected Rigidbody Rigidbody;
 
     protected float CameraAngleY;
     protected float CameraAngleX;
     protected float CameraAngleSpeed = 0.1f;
     protected float CameraPosY;
     protected float CameraPosSpeed = 0.1f;
 
     // Start is called before the first frame update
     void Start()
     {
         actions = GetComponent<LionActions>();
         lionPlayerControls = GetComponent<LionPlayerControls>();
         Rigidbody = GetComponent<Rigidbody>();
         
     }
 
     // Update is called once per frame
     void Update()
     {
        
         var input = new Vector3(LeftJoystick.inputVector.x, 0, LeftJoystick.inputVector.y);
         var vel = Quaternion.AngleAxis(CameraAngleY+180, Vector3.up) * input * 20f;
 
         Rigidbody.velocity = new Vector3(vel.x, Rigidbody.velocity.y, vel.z)*-1;
         if (input.magnitude > 0)
         {
             transform.rotation = Quaternion.AngleAxis(CameraAngleY + Vector3.SignedAngle(Vector3.forward, input.normalized, Vector3.up), Vector3.up);
         }
         else
         {
             transform.rotation =Quaternion.Euler(0,transform.rotation.eulerAngles.y,0) ;
             
         }
 
 
        CameraAngleY += TouchField.TouchDist.x * CameraAngleSpeed;
        
         
        Camera.main.transform.position = transform.position + Quaternion.AngleAxis(CameraAngleY, Vector3.up) * new Vector3(kameraX, kameraY, kameraZ);
      
 
         Camera.main.transform.rotation = Quaternion.LookRotation(transform.position + Vector3.up * 2f - Camera.main.transform.position, Vector3.up);
 
     
     }
 
 }
Now I am able to change the position of camera around player like a horizontal circle. Bu I want to do this also up and down like a verticle circle. I think ı should change the whole thing but ım not sure could someone please help me? ı,ve asked this question many times and still need a guide
               Comment
              
 
               
              It happen the same to me. Help me!! ,It happen the same to me. I need help!!
Answer by panim0_unity · Oct 05, 2019 at 01:40 PM
does somebody has a better way? a free cam around player by touch
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                