I'm currently writing an InputManager using Unity's "new" input system. The InputManager receives all player input via SendMessage() and disseminates it to the appropriate objects (player, UI, et cetera). In an attempt to adhere to SRP (single-responsibility principle), I want as much of the message massaging to occur in the InputManager as possible.
For player movement in the InputManager, I have the following:
public void OnMovement(InputValue input)
{
if (playerControl == null)
playerControl = player.GetComponent<PlayerControl>();
playerControl.OnMovement(input, playerMovementSpeed, cmCam.gameObject.transform.localEulerAngles);
}
on the PlayerControl script, I have:
void Update()
{
var q = Quaternion.Euler(cmCam.transform.localEulerAngles);
q.x = 0;
this.gameObject.transform.localPosition += q * moveVec * Time.deltaTime * playerMovementSpeed;
}
public void OnMovement(InputValue input, float speed, Vector3 cameraRotationAngle)
{
playerMovementSpeed = speed;
Vector2 inputVec = input.Get<Vector2>();
// Must multiply quat * vec | vec * quat causes an exception
//moveVec = Quaternion.Euler(cameraRotationAngle) * new Vector3(inputVec.x, 0, inputVec.y);
moveVec = new Vector3(inputVec.x, 0, inputVec.y);
}
I'm using the Quaternion of the CinemachineCamera so that as the camera rotates, directional movement accounts for it without having to stop and restart movement. At the same time, because it's a pseudo-isometric view, I want the x-value of the camera to be ignored (otherwise forward/backward movement has a skipping to it).
The current code works as-is, but querying and modifying the camera's returned transform value every frame via update seems less than ideal. I can't measure the performance impact because I can't figure out another way to do it.
Is there a way to make some sort of callback value that will give me `Quaternion(w, 0, y, z)' of that camera's transform every frame?
Ignore the cameraRotationAngle in the signature of playerControl.OnMovement - that was part of my initial attempt, but the value isn't updated until movement stops and restarts, so that will likely be removed.
