K
K
KraGen.Developer2021-09-05 18:26:29
Unity
KraGen.Developer, 2021-09-05 18:26:29

How to rotate target parallel to the camera but only on the x-axis?

Hello, in general, there is a Camera that monitors the object and there is a target that is parallel to the camera.
Target is a guide for the sphere (character) tobish sphere is pointed at the target. How to make this target rotate parallel to the camera BUT only relative to the X axis along the rest so that it does not move?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2021-09-29
@Andrei1805

If I correctly understood the essence of the question, then the problem is solved in one line. There is a GameObject target and a GameObject camera, the target rotates along with the camera in x.

target.transform.eulerAngles = new Vector3(camera.transform.rotation.ToEulerAngles().x * Mathf.Rad2Deg, 0, 0);

If, for example, you need not x, but y, then:
target.transform.eulerAngles = new Vector3(0, camera.transform.rotation.ToEulerAngles().y * Mathf.Rad2Deg, 0);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question