Super Bounce Script

I found a handy script to increase bounciness beyond 1.0 which the author called a “Power Bounce” but we can call it a “Super Bounce”. It works really well.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class HeadButt : MonoBehaviour
{
    public float str = 0.21f;
    public AudioClip HeadButtAudio;

    // Start is called before the first frame update
    void Start(){}

    // Update is called once per frame
    void Update(){}

    void OnCollisionEnter(Collision col)
    {

        Debug.Log("Hit!");
        
        if (col.gameObject.tag == "buttable")
        {
            Rigidbody rb = col.gameObject.GetComponent<Rigidbody>();
            rb.AddForce(rb.velocity * str, ForceMode.Impulse);
        }

        SFXPlayer.Instance.PlaySFX(HeadButtAudio, transform.position, new SFXPlayer.PlayParameters()
        {
            Pitch = Random.Range(0.9f, 1.1f),
            SourceID = -1,
            Volume = 1.0f
        }, 0.0f);

    }
}

The only thing left to do at a later date would be to try to accelerometer values from the headset and link that to the str (strength) parameter in the script.

Leave a Reply

Your email address will not be published. Required fields are marked *