Quantcast
Channel: Questions in topic: "gun"
Viewing all articles
Browse latest Browse all 592

Recoil with the FPS controller

$
0
0
Hello! I'm trying to create a recoil system to my current FPS game. The recoil system should rotate the camera, and then slowy change back to normal again, however the mouselook script locks the camera. To work around this, I put it in a bool to check if it could rotate. (mouselook.cs) public void LookRotation(Transform character, Transform camera) { if (active) { float yRot = CrossPlatformInputManager.GetAxis("Mouse X") * XSensitivity; float xRot = CrossPlatformInputManager.GetAxis("Mouse Y") * YSensitivity; m_CharacterTargetRot *= Quaternion.Euler(0f, yRot, 0f); m_CameraTargetRot *= Quaternion.Euler(-xRot, 0f, 0f); if (clampVerticalRotation) m_CameraTargetRot = ClampRotationAroundXAxis(m_CameraTargetRot); if (smooth) { character.localRotation = Quaternion.Slerp(character.localRotation, m_CharacterTargetRot, smoothTime * Time.deltaTime); camera.localRotation = Quaternion.Slerp(camera.localRotation, m_CameraTargetRot, smoothTime * Time.deltaTime); } else { character.localRotation = m_CharacterTargetRot; camera.localRotation = m_CameraTargetRot; } UpdateCursorLock(); } } However, this gave a very laggy look, and didn't work as i wanted. heres the recoil script public class Recoil : MonoBehaviour { [HideInInspector] public float recoil, max; [HideInInspector] public GameObject recoil_obj; private float rot, recoverSpeed; public void Update() { RecoilControl(); } public void AddRecoil() { rot += recoil / 10; MouseLook.active = false; Invoke("UnlockMouse", 0.2f); } void RecoilControl() { if(rot > 0) { rot -= Time.deltaTime * recoverSpeed; } if (rot < 0) rot = 0; Vector3 c_rot = recoil_obj.transform.localEulerAngles; recoil_obj.transform.localEulerAngles = new Vector3(c_rot.x + rot, c_rot.y,c_rot.z); } void UnlockMouse() { MouseLook.active = true; } }

Viewing all articles
Browse latest Browse all 592

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>