// Update is called once per frame void Update() { tempPlayer.transform.position = transform.position; tempPlayer.transform.rotation = transform.rotation; if (!gamepad.isKeyboard) { ajustedSensitivity = sensitivity; } else { ajustedSensitivity = mouseSensitivity; } //target = Cam_Raytrace.rayOutData[playerNum].collider.gameObject; if (transform.gameObject.GetComponent <Cam_Rotation>().isZooming) { if (!gamepad.isKeyboard) { ajustedSensitivity = adsSensitivity; } else { ajustedSensitivity = adsMouseSensitivity; } } if (!gamepad.isKeyboard) { if (transform.gameObject.GetComponent <Cam_Raytrace>().rayHit) { if (transform.gameObject.GetComponent <Cam_Raytrace>().rayOutData.collider.gameObject.name == "HitBox") { if (transform.parent.name != transform.gameObject.GetComponent <Cam_Raytrace>().rayOutData.collider.transform.parent.parent.name) { targetPos = transform.gameObject.GetComponent <Cam_Raytrace>().rayOutData.collider.transform.position; ajustedSensitivity = ajustedSensitivity / stickyAim; } } } if (transform.gameObject.GetComponent <Cam_Raytrace>().rayHit) { if (transform.gameObject.GetComponent <Cam_Raytrace>().rayOutData.collider.gameObject.name == "HitBox") { oldTargetPos = transform.gameObject.GetComponent <Cam_Raytrace>().rayOutData.collider.transform.position; } } } oldPos = player.transform.position; oldStick = gamepadStick.getAxis("Right"); }
//===================================================================================================================================================== void Update() { NoRecoil.transform.position = transform.position; CameraTurning(); CamreaZoom(); Vector2 cameraChange = new Vector2(0, 0); Vector2 cameraChangeNR = new Vector2(0, 0); if (gamePad.isKeyboard) { cameraChange.x = transform.GetComponent <Aim_Assist>().ajustedSensitivity.x *Input.GetAxis("Mouse X") + recoilEffect;//get mouse input cameraChange.y = transform.GetComponent <Aim_Assist>().ajustedSensitivity.y *Input.GetAxis("Mouse Y") + recoilEffectY; cameraChangeNR.y = transform.GetComponent <Aim_Assist>().ajustedSensitivity.y *Input.GetAxis("Mouse Y"); } if (!gamePad.isKeyboard) { cameraChange.x = transform.GetComponent <Aim_Assist>().ajustedSensitivity.x *gamePadStick.getAxis("Right").x + recoilEffect;//get stick input cameraChange.y = transform.GetComponent <Aim_Assist>().ajustedSensitivity.y *gamePadStick.getAxis("Right").y + recoilEffect; cameraChangeNR.y = transform.GetComponent <Aim_Assist>().ajustedSensitivity.y *gamePadStick.getAxis("Right").y; cameraChange = transform.GetComponent <Aim_Assist>().newAim(cameraChange); } recoilEffect = 0; recoilEffectY = 0; transform.Rotate(cam_upVec * cameraChange.x, Space.World); //rotate on local x axis NoRecoil.transform.Rotate(cam_upVec * cameraChange.x, Space.World); //rotate on local x axis //Debug.DrawRay(transform.position, cam_upVec, Color.green); cam_rightVec = Vector3.Cross(cam_upVec, transform.forward);//calculate new right vector cam_rightVec = Vector3.Normalize(cam_rightVec); //Checks the angle between camera's forward vector and the normal of the surface the player is on if ((Vector3.Angle(transform.forward, cam_upVec) <= restrictAngle) && (cameraChange.y > 0)) //If the angle between the two vectors is less than a certain degree and the player is trying to look up { cameraChange.y = -1.0f; // rotate down instead } else if ((Vector3.Angle(transform.forward, cam_upVec) >= (180 - restrictAngle)) && (cameraChange.y < 0)) //If the angle between the two vectors is bigger than a certain degree and the player is trying to look down { cameraChange.y = 1.0f; // rotate up instead } else //Just rotates normally { //Debug.Log(Vector3.Angle(NoRecoil.transform.forward, player.transform.forward) +" "+ Vector3.Angle(transform.forward, player.transform.forward)); if (Vector3.Angle(NoRecoil.transform.forward, player.transform.forward) <= Vector3.Angle(transform.forward, player.transform.forward) || cameraChange.y > 0) { NoRecoil.transform.Rotate(cam_rightVec * -cameraChangeNR.y, Space.World); } transform.Rotate(cam_rightVec * -cameraChange.y, Space.World);//rotate on local y axis (netagive to function like standard FPS controls) //Debug.DrawRay(transform.position, cam_rightVec, Color.red); if (Vector3.Angle(NoRecoil.transform.forward, player.transform.up) < Vector3.Angle(transform.forward, player.transform.up)) { NoRecoil.transform.rotation = transform.rotation; } } cam_forwardVec = transform.TransformDirection(Vector3.forward);//seting forward //sets camrea to players position transform.position = camPos.transform.position; //transform.rotation = NoRecoil.transform.rotation; Debug.DrawRay(NoRecoil.transform.position, NoRecoil.transform.forward); }