void SpawnParticles() { Vector3 position = Vector3.zero; Vector3 normal = Vector3.zero; CGroundedInfo groundInfo = m_CharacterController.GetCollider().GetGroundedInfo(); CSideCastInfo sideCastInfo = m_CharacterController.GetCollider().GetSideCastInfo(); bool valid = false; if (groundInfo.m_IsGrounded) { position = groundInfo.GetPoint(); normal = new Vector3(groundInfo.GetNormal().x, groundInfo.GetNormal().y, 0.0f); valid = true; } else if (sideCastInfo.m_WallCastCount >= 2) { position = sideCastInfo.GetSidePoint(); normal = sideCastInfo.GetSideNormal(); valid = true; } else { position = m_Collider.GetDownCenter() - m_Collider.GetUpDirection() * m_Collider.GetRadius(); normal = m_Collider.GetUpDirection(); valid = true; } if (valid) { m_ParticleSystem.transform.position = position; m_ParticleSystem.transform.LookAt(position + normal, Vector3.back); m_ParticleSystem.Emit(m_EmissionCount); } }
void FixedUpdate() { if (m_Collider.IsGrounded()) { CGroundedInfo groundedInfo = m_Collider.GetGroundedInfo(); Vector2 currentVel = m_Collider.GetVelocity(); float dot = Vector3.Dot(currentVel, CState.GetDirectionAlongNormal(currentVel, groundedInfo.GetNormal())); if (dot >= m_LowThreshold) { int emission = m_LowEmissionCount; if (dot >= m_HighThreshold) { emission = m_HighEmissionCount; } m_ParticleSystem.transform.position = groundedInfo.GetPoint(); m_ParticleSystem.transform.LookAt(groundedInfo.GetPoint() + new Vector3(groundedInfo.GetNormal().x, groundedInfo.GetNormal().y, 0.0f), Vector3.back); m_ParticleSystem.Emit(emission); } } }