Search Unity

RotateAround without Z changing

Discussion in 'Scripting' started by demozbox, Aug 29, 2015.

  1. demozbox

    demozbox

    Joined:
    Nov 26, 2014
    Posts:
    83
    i want to rotate camera arount an obj and i need it to do without Z changing.
    [syntax=csharp]
    void Update(){
    Vector3 v3;
    v3.x = Input.GetAxes("Vertical");//-_uj.TouchAxisRight().y;
    v3.y = Input.GetAxes("Horizontal");//_uj.TouchAxisRight().x;
    v3.z = 0;
    v3 = _camTransform.TransformDirection(v3);
    v3.z = 0;
    _camTransform.RotateAround(_target.position, v3, 200* Time.deltaTime);
    }[/syntax]
    this is the third person view camera and i cannot add something like(Below) at the end of code
    [syntax=csharp]
    _transform.eulerAngles = new Vector3(_transform.eulerAngles.x, _transform.eulerAngles.y,0);[/syntax]
    because it will make rotation and then make fixing, which can be seen by user.
    so, how to fix v3 before i put it into RotateAround method
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    Why can't you just set the _camTransform's z to 0 immediately after RotateAround()? Why do you have to set another transform first?
     
  3. demozbox

    demozbox

    Joined:
    Nov 26, 2014
    Posts:
    83
    ive done it with this
    Code (CSharp):
    1.  Vector3 v3 = new Vector3(_transform.eulerAngles.x - swipeDelta.y, _transform.eulerAngles.y + swipeDelta.x, 0);
    2.         v3.x = ClampAngle(v3.x, minimumY, maximumY);
    3.         Quaternion rotationTo = Quaternion.Euler(v3);
    4.         _transform.rotation = Quaternion.Slerp(_transform.rotation, rotationTo, Time.deltaTime * _camRotSpeed);