/// <summary> /// /// </summary> protected override void Start() { base.Start(); if (!rigidbody || !collider) { this.enabled = false; } // cache rigidbody vars if (rigidbody != null) { m_DefaultGravity = rigidbody.useGravity; m_DefaultDrag = m_Transform.rigidbody.drag; m_DefaultAngularDrag = m_Transform.rigidbody.angularDrag; } // for normal interaction type InteractType = vp_InteractType.Normal; m_InteractManager = GameObject.FindObjectOfType(typeof(vp_FPInteractManager)) as vp_FPInteractManager; }
/// <summary> /// /// </summary> protected override void Start() { base.Start(); if (!GetComponent <Rigidbody>() || !GetComponent <Collider>()) { this.enabled = false; } // cache rigidbody vars if (GetComponent <Rigidbody>() != null) { m_DefaultGravity = GetComponent <Rigidbody>().useGravity; m_DefaultDrag = m_Transform.GetComponent <Rigidbody>().drag; m_DefaultAngularDrag = m_Transform.GetComponent <Rigidbody>().angularDrag; } // for normal interaction type InteractType = vp_InteractType.Normal; m_InteractManager = GameObject.FindObjectOfType(typeof(vp_FPInteractManager)) as vp_FPInteractManager; }
/// <summary> /// /// </summary> protected override void Start() { base.Start(); if (!rigidbody || !collider) this.enabled = false; // cache rigidbody vars if (rigidbody != null) { m_DefaultGravity = rigidbody.useGravity; m_DefaultDrag = m_Transform.rigidbody.drag; m_DefaultAngularDrag = m_Transform.rigidbody.angularDrag; } // for normal interaction type InteractType = vp_InteractType.Normal; m_InteractManager = GameObject.FindObjectOfType(typeof(vp_FPInteractManager)) as vp_FPInteractManager; }
/// <summary> /// Stops the grab state. /// </summary> protected virtual void StopGrab() { // reset grab and fetch states m_IsGrabbed = false; m_FetchProgress = 1.0f; // stop listening to camera footsteps m_Camera.BobStepCallback -= Footstep; // ready the weapon we were using m_Player.SetWeapon.TryStart(m_LastWeaponEquipped); // reset the object back to it's defaults if (m_Transform.rigidbody != null) { m_Transform.rigidbody.useGravity = m_DefaultGravity; m_Transform.rigidbody.drag = m_DefaultDrag; m_Transform.rigidbody.angularDrag = m_DefaultAngularDrag; } // allow player to collide with this object again if (!m_Player.Dead.Active) // NOTE: doing the below while player is dead will cause a crash { if (vp_Utility.IsActive(m_Transform.gameObject) && m_Controller.Transform.collider.enabled && m_Transform.collider.enabled) Physics.IgnoreCollision(m_Controller.Transform.collider, m_Transform.collider, false); } Vector3 finalRotation = m_Transform.eulerAngles; // remove this object from being a child of the camera m_Transform.parent = null; m_Transform.eulerAngles = finalRotation; // reset object's velocity if (m_Transform.rigidbody != null) { m_Transform.rigidbody.velocity = Vector3.zero; m_Transform.rigidbody.angularVelocity = Vector3.zero; } // throw the object if fire button used if (vp_Input.GetButtonDown("Attack")) { vp_AudioUtility.PlayRandomSound(m_Audio, ThrowSounds, SoundsPitch); if (m_Transform.rigidbody != null) { m_Transform.rigidbody.AddForce(m_Player.Velocity.Get() + m_Player.Forward.Get() * ThrowStrength, ForceMode.Impulse); if (AllowThrowRotation) m_Transform.rigidbody.AddTorque(m_Camera.Transform.forward * (Random.value > 0.5f ? 0.5f : -0.5f) + m_Camera.Transform.right * (Random.value > 0.5f ? 0.5f : -0.5f), ForceMode.Impulse); } } else // otherwise perform a normal drop { vp_AudioUtility.PlayRandomSound(m_Audio, DropSounds, SoundsPitch); if (m_Transform.rigidbody != null) m_Transform.rigidbody.AddForce(m_Player.Velocity.Get() + m_Player.Forward.Get(), ForceMode.Impulse); } if (m_InteractManager == null) m_InteractManager = GameObject.FindObjectOfType(typeof(vp_FPInteractManager)) as vp_FPInteractManager; // disallow the crosshair to change again for half a second m_InteractManager.CrosshairTimeoutTimer = Time.time + 0.5f; // restore original camera pitch limit (will a small delay, // or it won't always take effect) vp_Timer.In(0.1f, delegate() { m_Camera.RotationPitchLimit.y = m_OriginalPitchDownLimit; }); }
/// <summary> /// /// </summary> protected override void Start() { base.Start(); if (!GetComponent<Rigidbody>() || !GetComponent<Collider>()) this.enabled = false; // cache rigidbody vars if (GetComponent<Rigidbody>() != null) { m_DefaultGravity = GetComponent<Rigidbody>().useGravity; m_DefaultDrag = m_Transform.GetComponent<Rigidbody>().drag; m_DefaultAngularDrag = m_Transform.GetComponent<Rigidbody>().angularDrag; } // for normal interaction type InteractType = vp_InteractType.Normal; m_InteractManager = GameObject.FindObjectOfType(typeof(vp_FPInteractManager)) as vp_FPInteractManager; }
/// <summary> /// Stops the grab state. /// </summary> protected virtual void StopGrab() { // reset grab and fetch states m_IsGrabbed = false; m_FetchProgress = 1.0f; // stop listening to camera footsteps m_Camera.BobStepCallback -= Footstep; // ready the weapon we were using m_Player.SetWeapon.TryStart(m_LastWeaponEquipped); // reset the object back to it's defaults if (m_Transform.rigidbody != null) { m_Transform.rigidbody.useGravity = m_DefaultGravity; m_Transform.rigidbody.drag = m_DefaultDrag; m_Transform.rigidbody.angularDrag = m_DefaultAngularDrag; } // allow player to collide with this object again if (!m_Player.Dead.Active) // NOTE: doing the below while player is dead will cause a crash { if (vp_Utility.IsActive(m_Transform.gameObject) && m_Controller.Transform.collider.enabled && m_Transform.collider.enabled) { Physics.IgnoreCollision(m_Controller.Transform.collider, m_Transform.collider, false); } } Vector3 finalRotation = m_Transform.eulerAngles; // remove this object from being a child of the camera m_Transform.parent = null; m_Transform.eulerAngles = finalRotation; // reset object's velocity if (m_Transform.rigidbody != null) { m_Transform.rigidbody.velocity = Vector3.zero; m_Transform.rigidbody.angularVelocity = Vector3.zero; } // throw the object if fire button used if (vp_Input.GetButtonDown("Attack")) { vp_AudioUtility.PlayRandomSound(m_Audio, ThrowSounds, SoundsPitch); if (m_Transform.rigidbody != null) { m_Transform.rigidbody.AddForce(m_Player.Velocity.Get() + m_Player.Forward.Get() * ThrowStrength, ForceMode.Impulse); if (AllowThrowRotation) { m_Transform.rigidbody.AddTorque(m_Camera.Transform.forward * (Random.value > 0.5f ? 0.5f : -0.5f) + m_Camera.Transform.right * (Random.value > 0.5f ? 0.5f : -0.5f), ForceMode.Impulse); } } } else // otherwise perform a normal drop { vp_AudioUtility.PlayRandomSound(m_Audio, DropSounds, SoundsPitch); if (m_Transform.rigidbody != null) { m_Transform.rigidbody.AddForce(m_Player.Velocity.Get() + m_Player.Forward.Get(), ForceMode.Impulse); } } if (m_InteractManager == null) { m_InteractManager = GameObject.FindObjectOfType(typeof(vp_FPInteractManager)) as vp_FPInteractManager; } // disallow the crosshair to change again for half a second m_InteractManager.CrosshairTimeoutTimer = Time.time + 0.5f; // restore original camera pitch limit (will a small delay, // or it won't always take effect) vp_Timer.In(0.1f, delegate() { m_Camera.RotationPitchLimit.y = m_OriginalPitchDownLimit; }); }