Hey,
I tried to make a 1st Person game and I have some Problems with the camera movement.
When I press w, the camera should move in x-direction by 1.
How could I do this?
My script so far:
bool horizontalDir = Input.GetButton("Horizontal1"); //Button W
bool verticalDir = Input.GetButton("Vertical1"); //Button D
bool horizontalDirn = Input.GetButton("Horizontal2"); //Button S (n = negative)
bool verticalDirn = Input.GetButton("Vertical2"); //Button A (n = negative)
bool jump = Input.GetButton("Jump"); //Space
float camPosX = cam.transform.position.x; //variable with the X-value
float camPosZ = cam.transform.position.z; //variable with the Z-value
float camPosY = cam.transform.position.y; //variable with the Y-value
cam = GetComponent<Camera>();
if (horizontalDir == true)
{
camPosX = Camera.main.gameObject.transform.position.x + moveSpeed;
}
if (verticalDir == true)
{
camPosZ = Camera.main.gameObject.transform.position.z + moveSpeed;
}
if (horizontalDirn == true)
{
camPosX = Camera.main.gameObject.transform.position.x - moveSpeed;
}
if (verticalDirn == true)
{
camPosZ = Camera.main.gameObject.transform.position.z - moveSpeed;
}
if (jump == true)
{
camPosY = Camera.main.gameObject.transform.position.y + jumpHeight;
camPosY = Camera.main.gameObject.transform.position.y - jumpHeight;
}
cam.gameObject.transform.position.x = camPosX; //does not work
cam.gameObject.transform.position.y = camPosY; //does not work
cam.gameObject.transform.position.z = camPosZ; //does not work