Better Kicking
parent
1549ac217d
commit
89b1ba73ee
|
@ -1,7 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 21037762408ec1942ae9b93b6b1413e7
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue