Exemple #1
0
    ///////////////////////////////////////////////////////////
    // by default a rigidbody will not come to rest in a
    // manner reminiscent of a brass shell, no matter what
    // physics material you have set on it. this method
    // determines if the shell should rest in its upright or
    // tipped over angle, for more realistic shell motion.
    ///////////////////////////////////////////////////////////
    protected void DecideRestAngle()
    {
        float up = Mathf.Abs(transform.eulerAngles.x - 270);		// see how close shell is to its upright position

        // if shell is close to standing up with its (heavier) base
        // toward the ground
        if (up < 55)
        {

            // see if the ground is flat
            Ray ray = new Ray(transform.position, -Vector3.up);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, 1))
            {
                // if so, we will force the shell to its upright position
                if (hit.normal == Vector3.up)
                {
                    m_RestAngleFunc = UpRight;
                    rigidbody.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;
                }
            }

            return;

        }

        // either the shell is fairly tilted or the ground is not flat,
        // so we will force the shell to lie down
        m_RestAngleFunc = TippedOver;
    }
Exemple #2
0
    ///////////////////////////////////////////////////////////
    // by default a rigidbody will not come to rest in a
    // manner reminiscent of a brass shell, no matter what
    // physics material you have set on it. this method
    // determines if the shell should rest in its upright or
    // tipped over angle, for more realistic shell motion.
    ///////////////////////////////////////////////////////////
    protected void DecideRestAngle()
    {
        float up = Mathf.Abs(transform.eulerAngles.x - 270);                    // see how close shell is to its upright position

        // if shell is close to standing up with its (heavier) base
        // toward the ground
        if (up < 55)
        {
            // see if the ground is flat
            Ray        ray = new Ray(transform.position, -Vector3.up);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, 1))
            {
                // if so, we will force the shell to its upright position
                if (hit.normal == Vector3.up)
                {
                    m_RestAngleFunc       = UpRight;
                    rigidbody.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;
                }
            }

            return;
        }

        // either the shell is fairly tilted or the ground is not flat,
        // so we will force the shell to lie down
        m_RestAngleFunc = TippedOver;
    }
Exemple #3
0
    public List <AudioClip> m_BounceSounds = new List <AudioClip>();    // list of sounds to be randomly played on each ground impact


    ///////////////////////////////////////////////////////////
    //
    ///////////////////////////////////////////////////////////
    void Start()
    {
        m_RestAngleFunc = null;

        m_RemoveTime = Time.time + LifeTime;
        m_RestTime   = Time.time + (LifeTime * 0.25f);

        rigidbody.maxAngularVelocity = 100;                     // allow shells to spin faster than rigidbody default

        audio.playOnAwake  = false;
        audio.dopplerLevel = 0.0f;
    }
    void OnEnable()
    {
        m_RestAngleFunc = null;

        m_RemoveTime = Time.time + LifeTime;
        m_RestTime   = Time.time + (LifeTime * 0.25f);

        m_Rigidbody.maxAngularVelocity = 100;                   // allow shells to spin faster than rigidbody default
        m_Rigidbody.velocity           = Vector3.zero;
        m_Rigidbody.angularVelocity    = Vector3.zero;
        m_Rigidbody.constraints        = RigidbodyConstraints.None;

        collider.enabled = true;
    }
	void OnEnable()
	{
	
		m_RestAngleFunc = null;

		m_RemoveTime = Time.time + LifeTime;
		m_RestTime = Time.time + (LifeTime * 0.25f);
		
		m_Rigidbody.maxAngularVelocity = 100;		// allow shells to spin faster than rigidbody default
		m_Rigidbody.velocity = Vector3.zero;
		m_Rigidbody.angularVelocity = Vector3.zero;
		m_Rigidbody.constraints = RigidbodyConstraints.None;
		
		GetComponent<Collider>().enabled = true;
	
	}
Exemple #6
0
    public List <AudioClip> m_BounceSounds = new List <AudioClip>();    // list of sounds to be randomly played on each ground impact


    /// <summary>
    ///
    /// </summary>
    void Start()
    {
        m_Transform = transform;
        m_Rigidbody = GetComponent <Rigidbody>();
        m_Audio     = GetComponent <AudioSource>();

        m_RestAngleFunc = null;

        m_RemoveTime = Time.time + LifeTime;
        m_RestTime   = Time.time + (LifeTime * 0.25f);

        m_Rigidbody.maxAngularVelocity = 100;                   // allow shells to spin faster than rigidbody default

        GetComponent <AudioSource>().playOnAwake  = false;
        GetComponent <AudioSource>().dopplerLevel = 0.0f;
    }
Exemple #7
0
    ///////////////////////////////////////////////////////////
    //
    ///////////////////////////////////////////////////////////
    void Start()
    {
        m_RestAngleFunc = null;

        m_RemoveTime = Time.time + LifeTime;
        m_RestTime = Time.time + (LifeTime * 0.25f);

        rigidbody.maxAngularVelocity = 100;		// allow shells to spin faster than rigidbody default

        audio.playOnAwake = false;
        audio.dopplerLevel = 0.0f;
    }
    ///////////////////////////////////////////////////////////
    //
    ///////////////////////////////////////////////////////////
    void Start()
    {
        m_RestAngleFunc = null;

        m_RemoveTime = Time.time + LifeTime;
        m_RestTime = Time.time + (LifeTime * 0.25f);

        GetComponent<Rigidbody>().maxAngularVelocity = 100;		// allow shells to spin faster than rigidbody default

        GetComponent<AudioSource>().playOnAwake = false;
        GetComponent<AudioSource>().dopplerLevel = 0.0f;
    }