aernbau
1
I was trying to make a camera that’s relative to the character, for a robot combat game like Zone of the Enders, Project Nimbus, Strike Suit Zero/Infinity, etc. and I can’t get rotation/localRotation to work properly.
float hor = Input.GetAxis("Mouse X") * smooth;
float ver = Input.GetAxis("Mouse Y") * smooth;
/*
if(!target.IsGrounded())
target.transform.Rotate(-ver, hor, 0);
else
target.transform.Rotate(0, hor, 0);
*/
/*
if(!target.IsGrounded())
target.transform.localRotation = Quaternion.Euler(-ver, hor, 0);
else
target.transform.localRotation = Quaternion.Euler(0, hor, 0);
*/
The target is a GameObject. The grounding is irrelevant. If I use Rotate, it rotates ‘alright’, but not how I want to. If I use rotation/localRotation, it rotates, but only for 1 frame, then returns to the default position. transform.eulerAngles does the same thing. Even if I make an empty game object that is supposed to just exist and spin something by its local rotation, it will not.
I am pretty new to Unity, not new to coding so it doesn’t make sense to me how this doesn’t work. Please help.
aernbau
2
Don’t you love it how you find the answer only after trying to ask someone else?
I’ve made 2 extra floats to add on the mouse movement.
Pretty sure I’ll find out I’ve done something wrong on some other part, but for now…
float hor_mouse = Input.GetAxis("Mouse X");
float ver_mouse = Input.GetAxis("Mouse Y");
hor += hor_mouse;
ver += ver_mouse;
//testtarget.transform.Rotate(-ver, 2, 0);
testtarget.transform.localRotation = Quaternion.Euler(-ver,hor,0);
Yay.