- Home /
Maintain direction regardless of orientation (2)
Hi everyone,
I'm pretty new to Unity. I've been watching tutorials, read the threads I could find (this one is close) and references, but been stuck for a couple days now and I would really like to ask. I have set a capsule as a parent and a camera as a child. It is basically a first person controller. The capsule handles all the movements and has a CharacterController attached to it. The way it is currently moved is this:
var myController : CharacterController;
myController = GetComponent(CharacterController);
var movementVector : Vector3 = Vector3
(Input.GetAxis("Horizontal")*sp*Time.deltaTime,
0,
Input.GetAxis("Vertical")*sp*Time.deltaTime);
// MOVE!
myController.Move(movementVector);
then I attached the MouseLook script to the camera child to handle rotation. I've checked and it goes through here:
if (axes == RotationAxes.MouseXAndY)
{
float rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX;
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
rotationDeg = new Vector3(-rotationY, rotationX, 0);
transform.localEulerAngles = rotationDeg;
}
In the end, I'm able to move and rotate, but when I rotate the axis do not change their orientation. I've read about and tried
transform.TransformDirection(rotationDeg);
but it does not seem to work as it changes the axis in the scene panel but the keys keep being mapped to the original axis orientation. Is this a matter of local vs global? I can't seem to get it right.
Please don't mind if one script is in C# and the other in Js. It's not an issue of passing values from C# to Js. The problem is just with the principle. Thanks in advance.
Cheers,
Ruggero