public void fireBall(float powerScalar, Vector3 fireDir, Vector3 hitPoint) { HOAudioManager.FireBall(); GameManager.Rules.OnBallFired(); m_slowTime = 0; Vector3 fireForce = fireDir * powerScalar * ConstantData.GetPoolDatas().MaxImpulse; m_rigidbody.AddForceAtPosition(fireForce, hitPoint, ForceMode.Impulse); m_state = State.ROLL; OpenDrag(); }
public virtual void Awake() { m_rigidbody = gameObject.GetComponent <Rigidbody>(); m_ShadowRenderer = GetComponent <BallShadowRenderer>(); m_LightRenderer = transform.FindChild("RefLight").GetComponent <Follower>(); m_FocusRenderer = transform.FindChild("Focus").GetComponent <Follower>(); sphereCollider = gameObject.GetComponent <SphereCollider>(); m_Mesh = GetComponent <MeshRenderer>(); //m_BallPhysicalDrag = GetComponent<BallPhysicalDrag>(); m_Radius = sphereCollider.radius * transform.localScale.x; m_BallPhysicalDrag = PhysicalSupportTools.PhysicalDragTo(gameObject, ConstantData.GetPoolDatas().BallDrag, ConstantData.GetPoolDatas().BallAngularDrag); //m_AngularVelocityCorrection = PhysicalSupportTools.AngularVelocityCorrectionTo(gameObject, m_rigidbody, m_Radius); m_PhysicMaterial = collider.sharedMaterial; }
private void VelocityDrag() { if (m_Rigidbody.isKinematic) { return; } m_Velocity = m_Rigidbody.velocity; #if UNITY_EDITOR float f = m_Velocity.magnitude - ConstantData.GetPoolDatas().BallDrag *Time.fixedDeltaTime; #else float f = m_Velocity.magnitude - m_VelocityDrag * Time.fixedDeltaTime; #endif if (f <= 0) { m_Rigidbody.velocity = Vector3.zero; } else { m_Rigidbody.velocity = m_Velocity.normalized * f; } }
private void AngularVelocityDrag() { if (m_Rigidbody.isKinematic) { return; } m_AngularVelocity = m_Rigidbody.angularVelocity; float a = (Mathf.Abs(m_AngularVelocity.y) < 10) ? 1 : m_AngularVelocity.magnitude * .1f; float d = ConstantData.GetPoolDatas().BallAngularDrag *Time.fixedDeltaTime *a; float f = Mathf.Abs(m_AngularVelocity.y) - d; if (f <= 0) { m_AngularVelocity.y = 0; } else { m_AngularVelocity.y = m_AngularVelocity.y < 0 ? -f : f; } m_Rigidbody.angularVelocity = m_AngularVelocity; }
void Awake() { if (!Application.isPlaying) { awakeAtPlaying = false; return; } awakeAtPlaying = true; skin = Resources.Load <GUISkin>("GUISkin/PoolGUISkin"); m_DataAsset = ConstantData.GetPoolDatas(); m_DataAssetTemp = StreamTools.Clone <PoolDataAsset>(m_DataAsset); m_Railpm = Resources.LoadAssetAtPath <PhysicMaterial>("Assets/PhysXMaterial/Wall.physicMaterial"); m_Ballpm = Resources.LoadAssetAtPath <PhysicMaterial>("Assets/PhysXMaterial/Ball.physicMaterial"); if (m_Railpm == null || m_Ballpm == null) { Debug.LogError("Physic material is null"); } m_Railpm.bounciness = m_DataAsset.RailBounciness; m_Ballpm.bounciness = m_DataAsset.BallBounciness; }