1
\$\begingroup\$

Holder contains camera and rotates around player

Camera looks like in diablo, titan quest, grim dawn, etc

I cant rotate camera to negative angle values

My code:

public void ChangeRotation(float val){
    if(isTurning)
        return;
    isTurning = true;
    needAngleY += val;
}

void Turning(){
    Quaternion quatertion = transform.rotation;
    Vector3 eulerAngle = new Vector3(0, quatertion.eulerAngles.y, 0);

    if(needAngleY - eulerAngle.y < 0.2f){
        if(needAngleY == 360 || needAngleY == -360){
            needAngleY = 0;
        }
        eulerAngle.y = needAngleY;
        isTurning = false;
    } else {
        eulerAngle.y = Mathf.Lerp(eulerAngle.y, needAngleY, timeRotation * Time.deltaTime);
    }
    m_Compas.rotation = eulerAngle.y;
    quatertion.eulerAngles = eulerAngle;
    parentTran.rotation = quatertion;
}
\$\endgroup\$
1
\$\begingroup\$

You can use transform.RotateAround() to specify a rotation axis for your camera. If you pass in the player transform.position as the first param and the axis you want to rotate around as the second, this should get you what you want.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.