- Home /
How can you move main camera along x,z axis without moving along y axis with DotA/LoL mouse control
So pretty much what I've done is I've made a camera control script that takes the movement from a mouse across the window and used that to move the camera across the scene, now I've tried to make it move using transform.translate but it always seemed to move across the y axis and eventually going through the 'floor' of the whole scene if I went far enough back which is obviously a problem, so than I tried to make it change the transform.position.x/z values directly which is working but the problem I have now is that the camera has a 45 y angle rotation so if you move the mouse up and down the camera goes diagonally instead of the way you're moving the mouse, now I thought I could combat this using Trigonometry but I'm sort of stuck as to how I should apply it.
Here's what I have so far
var horizontalSpeed : float = 0.4; //Speed to move camera along horizontal axis.
var verticalSpeed : float = 0.4; //Speed to move camera along vertical axis.
var key : KeyCode = KeyCode.Mouse2; //Keycode to initiate camera movement.
function Update ()
{
// If button pressed, camera will move along mouse axis.
if (Input.GetKey(key))
{
var h : float = horizontalSpeed * -Input.GetAxis ("Mouse Y"); //How much to move along the z axis
var v : float = verticalSpeed * -Input.GetAxis ("Mouse X"); //How much to move along the x axis
//Adding 'h' and 'v' values to move along the x,z axis'
transform.position.z += h;
transform.position.x += v;
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613135903im_/https://answers.unity.com/themes/thub/images/avi.jpg)