示例#1
0
    void OnCollisionEnter(Collision col)
    {
        if (col.collider.tag == "Glove")
        {
            bagRigidBody.useGravity = true;
            hasBeenHit = true;
            //Gives it an impulse. This makes the player feel stong and the starting punching bag to "Team Rocket Away"
            float bonusForce = col.collider.gameObject.GetComponent <PhysicsProperties>().gloveForceMultiplier;

            //Determine speed of punch, use to increase speed of bag.

            Vector3 punchSpeed = col.collider.gameObject.GetComponent <PhysicsProperties>().gloveSpeed;
            bagRigidBody.AddForce(col.impulse.normalized * bonusForce * punchSpeed.magnitude, ForceMode.Impulse);

            //Play punch sound clip
            punchSound = col.collider.gameObject.GetComponent <GloveSoundManager>();
            punchSound.PlayPunchSound();

            //Simulate some haptic feedback
            if (col.collider.gameObject.GetComponentInParent <GloveController>() != null)
            {
                col.collider.gameObject.GetComponentInParent <GloveController>().Rumble();
            }
            else
            {
                Debug.Log("Glove's parent does not have a GloveController Script");
            }
        }
    }
示例#2
0
    void OnCollisionEnter(Collision col)
    {
        GameObject collidedObject    = col.collider.gameObject;
        Rigidbody  collidedRigidBody = collidedObject.GetComponent <Rigidbody>();

        if (collidedObject.tag == "Right" || collidedObject.tag == "Left")
        {
            return;
        }
        if (collidedObject.tag == "Mine")
        {
            collidedObject.GetComponent <MineController> ().Explode();
        }
        if (collidedRigidBody == null)
        {
            Debug.Log("Collision object has no rigid body");
            Debug.Log(collidedObject.name);
        }
        if (collidedRigidBody != null)
        {
            //collision.relativevelocity was not returning a correct value, instead I'll use the addition of
            //the controller's velocity and the object collided with. Also the negative is needed to make the
            //relative velocity be relative to the object hit.
            Vector3 relativeVel = -(device.velocity + collidedRigidBody.velocity);


            //Find direction of rebound
            Vector3 forceDir = gameManager.FindForceDir(relativeVel, col.contacts[0].normal);

            //Feed these to the debugger.
            forDebugging [0] = "Device velocity: " + device.velocity.ToString();
            forDebugging [1] = "Relative Velocity: " + relativeVel.ToString();
            forDebugging [2] = "Force Direction: " + forceDir.ToString();
            vectorsRecorded  = false;

            //Amplify hit with the moving average squared and an arbitrary scalar.
            //float bonusPower = (float)Math.Pow(movingAvgDisplacement, 2f) * gloveProperties.gloveForceMultiplier;
            float bonusPower = device.velocity.sqrMagnitude;

            //Apply force as an impulse using the normalized direction found with FindForceDir()
            collidedRigidBody.AddForce(forceDir.normalized * bonusPower, ForceMode.Impulse);
            collidedRigidBody.useGravity = true;

            if (collidedObject.tag == "Bomb")
            {
                collidedObject.GetComponent <BombController>().hasBeenHit = true;
            }
            if (collidedObject.tag == "Bag")
            {
                gameManager.StartGame();
            }

            //Play punch sound clip
            gloveSoundManager.PlayPunchSound();

            //Simulate some haptic feedback
            Rumble();
        }
    }