How to make a gameObject's Y rotation being another gameObjects' X rotation
so i have an object and a camera and when the camera rotates up and down the x rotation is modified but when my object rotates up and down the y rotation is modified... whatever... I want my gameObject's y rotation being = to the camera's x rotation can you help me ? i searched many forums and posts and i didnt get it can you help me ? c#
Answer by jdean300 · Jun 15, 2016 at 07:25 AM
var cameraXRot = camera.rotation.eulerAngles.x;
var charactersEulerRot = character.rotation.eulerAngles;
character.rotation = Quaternion.Euler(charactersEulerRot.x, cameraXRot, characterEulerRot.z);
You might run into strange results if you're changing the x and z rotation of your character as well because Quaternions behave a little differently than x/y/z rotations (Euler), but this should work in most cases.
"'UnityEngine.GameObject' does not contain a definition for 'rotation' and no extension method 'rotation' accepting a first argument of type 'UnityEngine.GameObject' could be found (are you missing a using directive or an assembly reference?) (CS1061) (Assembly-CSharp) "
This Is The Error i get... How do i fix this ? ..
in my example character would have to be a Transform, so ins$$anonymous$$d use character.transform.rotation
it kinda works... my x and z of the character should be 0 so i put
character.transform.rotation = Quaternion.Euler(0, cameraXRot, 0);
and it kinda works but... my z and my x are moving too and the z is -90 and around that and it is fckt up so ... how do i fix? i dont know if what i modified is good