From 89b1ba73eebcb855b4a81947b5c01a5aff646489 Mon Sep 17 00:00:00 2001 From: Marc Gauch <34353267+marcgauch@users.noreply.github.com> Date: Fri, 8 Dec 2023 11:38:08 +0100 Subject: [PATCH] Better Kicking --- ...ernGuns_Handgun_v1.2_URP.unitypackage.meta | 7 ---- Assets/iamagun.cs | 33 +++++++++++++------ 2 files changed, 23 insertions(+), 17 deletions(-) delete mode 100644 Assets/Nokobot/Modern Guns - Handgun/URP/ModernGuns_Handgun_v1.2_URP.unitypackage.meta diff --git a/Assets/Nokobot/Modern Guns - Handgun/URP/ModernGuns_Handgun_v1.2_URP.unitypackage.meta b/Assets/Nokobot/Modern Guns - Handgun/URP/ModernGuns_Handgun_v1.2_URP.unitypackage.meta deleted file mode 100644 index 66407ef..0000000 --- a/Assets/Nokobot/Modern Guns - Handgun/URP/ModernGuns_Handgun_v1.2_URP.unitypackage.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 21037762408ec1942ae9b93b6b1413e7 -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/iamagun.cs b/Assets/iamagun.cs index 4a7463a..1ebad37 100644 --- a/Assets/iamagun.cs +++ b/Assets/iamagun.cs @@ -16,8 +16,9 @@ public class iamagun : MonoBehaviour private Vector3 offsetPosition; private Quaternion offsetRotation; + // Vibration variables - private float vibrationDelay = 0.05f; // Delay before the vibration starts + private float vibrationDelay = 0.1f; // Delay before the vibration starts private float vibrationDuration = 0.5f; // Duration of the vibration private float vibrationIntensity = 1.0f; // Intensity of the vibration @@ -37,7 +38,7 @@ public class iamagun : MonoBehaviour // Update is called once per frame void Update() { - if (!isKicking && OVRInput.IsControllerConnected(OVRInput.Controller.RTouch)) + if (OVRInput.IsControllerConnected(OVRInput.Controller.RTouch)) { // Get the local position and rotation of the controller Vector3 controllerLocalPosition = OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTouch); @@ -52,7 +53,9 @@ public class iamagun : MonoBehaviour transform.rotation = finalRotation; } - if (OVRInput.GetDown(shootButton)) + + + if (OVRInput.GetDown(shootButton) && !isKicking) { simpleShoot.StartShoot(); audio.Play(); @@ -79,7 +82,6 @@ public class iamagun : MonoBehaviour // Stop the vibration OVRInput.SetControllerVibration(0, 0, OVRInput.Controller.RTouch); } - IEnumerator KickGun() { // Set the kick animation flag to true @@ -88,14 +90,25 @@ public class iamagun : MonoBehaviour // Remember the initial rotation of the gun Quaternion initialRotation = transform.rotation; - // Rotate the gun on the X-axis - transform.Rotate(Vector3.right, -kickRotationAmount); + // Calculate the target rotation after the kick + Quaternion targetRotation = initialRotation * Quaternion.Euler(-kickRotationAmount, 0f, 0f); - // Wait for the kick duration - yield return new WaitForSeconds(kickDuration); + // Progress variable for smooth interpolation + float elapsedTime = 0f; - // Reset the rotation of the gun - transform.rotation = initialRotation; + while (elapsedTime < kickDuration) + { + // Interpolate the rotation smoothly + transform.rotation = Quaternion.Slerp(initialRotation, targetRotation, elapsedTime / kickDuration); + + // Increment the elapsed time + elapsedTime += Time.deltaTime; + + yield return null; + } + + // Ensure the final rotation is exactly the target rotation + transform.rotation = targetRotation; // Set the kick animation flag to false isKicking = false;