S
S
Stalder2015-12-27 12:33:31
Unity
Stalder, 2015-12-27 12:33:31

unity. Why is the rotation applied but the result is not visible?

Good day. The task is this: you need to rotate the character in the direction of the vector. The usual FPSController is used, it is referred to by the player in the second method.
Rotation of a separate camera is not offered.

void throwPortal(GameObject portal, bool isItFirst) {
        int x = Screen.width / 2;
        int y = Screen.height / 2;
        Ray ray = player.GetComponent<Camera>().ScreenPointToRay(new Vector3(x, y));
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit)) {
            if (isItFirst) firstDirection = hit.normal;
            else secondDirection = hit.normal;
            portal.transform.position = hit.point;
            portal.transform.rotation = Quaternion.LookRotation(hit.normal); // здесь вращение применяется
        }
    }

void OnTriggerEnter(Collider other) {
        Debug.Log("Inside trigger");
        if (other.tag == "Player") {
            other.transform.position = otherPortal.transform.position + otherPortal.transform.forward*1;
            if (isFirst) direction = other.GetComponent<ThrowPortal>().getDirectionSecond();
            else direction = other.GetComponent<ThrowPortal>().getDirectionFirst();

            Debug.Log("Изначальное вращение"+player.transform.rotation.ToString());
            Debug.Log("То что должно быть" + Quaternion.LookRotation(direction).ToString());
            player.transform.rotation =Quaternion.LookRotation(direction); //  !!! сам акт поворота !!!
            Debug.Log("Результат" + player.transform.rotation.ToString()); // показывает то же самое, что и вывод выше
            player.transform.position += direction * 5; // эта строка работает корректно, то бишь вектор не потерялся
        }
    }

I will be grateful for any help.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Daniil Basmanov, 2015-12-28
@Stalder

I understand that you took FPSController from standard unit scripts? It stores the rotation of the camera inside itself and applies it in each frame, your rotation value is simply overwritten by the controller.

Y
Yuri Ferley, 2015-12-27
@YuliyF

if (isFirst) direction = other.GetComponent<ThrowPortal>().getDirectionSecond();
            else direction = other.GetComponent<ThrowPortal>().getDirectionFirst();

shouldn't it be the other way around? if 1st time then take .getDirectionFirst(); - ?
what is the meaning of this line? add up the position and direction for some reason multiplied by 1 ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question