Better Kicking

pull/1/head
Marc Gauch 2023-12-08 11:38:08 +01:00
parent 1549ac217d
commit 89b1ba73ee
2 changed files with 23 additions and 17 deletions

View File

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: 21037762408ec1942ae9b93b6b1413e7
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -16,8 +16,9 @@ public class iamagun : MonoBehaviour
private Vector3 offsetPosition; private Vector3 offsetPosition;
private Quaternion offsetRotation; private Quaternion offsetRotation;
// Vibration variables // 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 vibrationDuration = 0.5f; // Duration of the vibration
private float vibrationIntensity = 1.0f; // Intensity 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 // Update is called once per frame
void Update() void Update()
{ {
if (!isKicking && OVRInput.IsControllerConnected(OVRInput.Controller.RTouch)) if (OVRInput.IsControllerConnected(OVRInput.Controller.RTouch))
{ {
// Get the local position and rotation of the controller // Get the local position and rotation of the controller
Vector3 controllerLocalPosition = OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTouch); Vector3 controllerLocalPosition = OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTouch);
@ -52,7 +53,9 @@ public class iamagun : MonoBehaviour
transform.rotation = finalRotation; transform.rotation = finalRotation;
} }
if (OVRInput.GetDown(shootButton))
if (OVRInput.GetDown(shootButton) && !isKicking)
{ {
simpleShoot.StartShoot(); simpleShoot.StartShoot();
audio.Play(); audio.Play();
@ -79,7 +82,6 @@ public class iamagun : MonoBehaviour
// Stop the vibration // Stop the vibration
OVRInput.SetControllerVibration(0, 0, OVRInput.Controller.RTouch); OVRInput.SetControllerVibration(0, 0, OVRInput.Controller.RTouch);
} }
IEnumerator KickGun() IEnumerator KickGun()
{ {
// Set the kick animation flag to true // Set the kick animation flag to true
@ -88,14 +90,25 @@ public class iamagun : MonoBehaviour
// Remember the initial rotation of the gun // Remember the initial rotation of the gun
Quaternion initialRotation = transform.rotation; Quaternion initialRotation = transform.rotation;
// Rotate the gun on the X-axis // Calculate the target rotation after the kick
transform.Rotate(Vector3.right, -kickRotationAmount); Quaternion targetRotation = initialRotation * Quaternion.Euler(-kickRotationAmount, 0f, 0f);
// Wait for the kick duration // Progress variable for smooth interpolation
yield return new WaitForSeconds(kickDuration); float elapsedTime = 0f;
// Reset the rotation of the gun while (elapsedTime < kickDuration)
transform.rotation = initialRotation; {
// 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 // Set the kick animation flag to false
isKicking = false; isKicking = false;