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);
        }
    }
示例#2
0
    public Vector2 GetDirectedInputMovement()
    {
        CGroundedInfo groundedInfo = m_ControlledCollider.GetGroundedInfo();

        if (groundedInfo.m_IsGrounded)
        {
            Vector2 input = groundedInfo.GetWalkDirection(new Vector2(transform.right.x, transform.right.y) * GetInputMovement().x);
            return(Vector2.ClampMagnitude(input, Vector2.Dot(input.normalized, GetInputMovement())));
        }
        return(new Vector2(GetInputMovement().x, 0));
    }
示例#3
0
    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);
            }
        }
    }
示例#4
0
    public Vector2 GetFriction(Vector2 a_Velocity, Vector2 a_CurrentForce, float a_FrictionConstant)
    {
        if (m_ControlledCollider.IsGrounded())
        {
            CGroundedInfo groundedInfo = m_ControlledCollider.GetGroundedInfo();

            Vector2 direction = -groundedInfo.GetWalkDirection(a_Velocity); //Opposite direction of velocity
            Vector2 maxFrictionSpeedChange = direction * a_FrictionConstant * Time.fixedDeltaTime;

            Vector2 velInDirection = Mathf.Abs(Vector2.Dot(a_Velocity, direction)) * direction;
            if (velInDirection.magnitude > maxFrictionSpeedChange.magnitude)
            {
                return(maxFrictionSpeedChange);
            }
            else
            {
                return(velInDirection);
            }
        }
        return(Vector2.zero);
    }