void FixedUpdate()
    {
        m_LastFixedUpdatePosition    = m_CurrentFixedUpdatePosition;
        m_CurrentFixedUpdatePosition = m_CapsuleCollider.GetCapsuleTransform().GetPosition();

        float difference = (m_CurrentFixedUpdatePosition - m_LastFixedUpdatePosition).magnitude;

        //We have likely been teleported. Interpolation would be annoying at this point.
        if (difference > m_InterpolationLimit)
        {
            m_LastFixedUpdatePosition = m_CurrentFixedUpdatePosition;
        }
    }
Beispiel #2
0
    void FixedUpdate()
    {
        //If the core of the capsule is clipping, the capsule is likely being squished.
        if (m_IsActive && m_ControlledCollider.GetCapsuleTransform().IsBeingSquished(m_SquishRadius))
        {
            m_IsBeingSquished = true;
        }
        else
        {
            m_IsBeingSquished = false;
        }
        //Apply ControlledCapsuleCollider transform
        m_CapsuleCollider.height = m_ControlledCollider.GetLength() + m_ControlledCollider.GetRadius() * 2.0f;

        //Detect collisions
        if (m_RigidBody)
        {
            m_RigidBody.MovePosition(transform.position);
        }
    }
Beispiel #3
0
    public override bool IsDangling()
    {
        bool hit = Physics.Raycast(m_CapsuleCollider.GetCapsuleTransform().GetDownCenter(), Vector3.down, m_CapsuleCollider.GetRadius() + m_CapsuleCollider.GetGroundedMargin(), m_CapsuleCollider.GetLayerMask());

        if (hit)
        {
            return(false);
        }
        else
        {
            return(true);
        }
    }
    void FixedUpdate()
    {
        //If no colpoints have been added this frame, but there were colpoints in the previous frame, then exit colpoints (with optional velocity boost)
        if (m_ColPoints.Count == 0)
        {
            if (m_PreviousAmountOfColPoints > 0)
            {
                ExitColpoints();
            }
            m_PreviousAmountOfColPoints = 0;
            m_LastMovement = Vector3.zero;
            m_ColPoints.Clear();
            return;
        }
        //Determine the total movement for the current frame by colpoints
        Vector3 currentMovement = Vector3.zero;

        for (int i = 0; i < m_ColPoints.Count; i++)
        {
            Vector3 diff = m_ColPoints[i].m_Transform.position - m_ColPoints[i].m_PrevPoint;
            currentMovement += diff;
            Quaternion rotationDifference = Quaternion.FromToRotation(m_ColPoints[i].m_PrevRot * Vector3.up, m_ColPoints[i].m_Transform.rotation * Vector3.up);
            if (m_ApplyRotationCorrection)
            {
                Vector3 newRelativePoint   = rotationDifference * m_ColPoints[i].m_PointRelativeToThis;
                Vector3 relativeDifference = newRelativePoint - m_ColPoints[i].m_PointRelativeToThis;
                currentMovement += relativeDifference;
            }
        }
        //If the total movement for this frame (compared to the previous frame's colpoint movement) is too large, detach the colpoints
        if (m_UseEscapeAcceleration && m_PreviousAmountOfColPoints > 0)
        {
            Vector3 velDifference = (currentMovement / Time.fixedDeltaTime) - (m_LastMovement / Time.fixedDeltaTime);
            for (int i = 0; i < m_ColPoints.Count; i++)
            {
                float normalDot = Vector3.Dot(m_ColPoints[i].m_Normal, velDifference);
                if (normalDot > 0)
                {
                    velDifference -= m_ColPoints[i].m_Normal * normalDot;
                }
            }

            if (velDifference.magnitude >= m_EscapeAcceleration)
            {
                m_ColPoints.Clear();
                ExitColpoints();
            }
        }
        m_LastMovement = currentMovement;
        //Apply ColPoints transformation to the character controller
        for (int i = 0; i < m_ColPoints.Count; i++)
        {
            //Position
            Vector3 diff = m_ColPoints[i].m_Transform.position - m_ColPoints[i].m_PrevPoint;
            m_ControlledCollider.GetCapsuleTransform().Move(diff);

            //Rotation
            Quaternion rotationDifference = Quaternion.FromToRotation(m_ColPoints[i].m_PrevRot * Vector3.up, m_ColPoints[i].m_Transform.rotation * Vector3.up);
            m_ControlledCollider.GetCapsuleTransform().SetUpDirection(rotationDifference * m_ControlledCollider.GetCapsuleTransform().GetUpDirection());
            //Offset for rotation
            if (m_ApplyRotationCorrection)
            {
                Vector3 newRelativePoint   = rotationDifference * m_ColPoints[i].m_PointRelativeToThis;
                Vector3 relativeDifference = newRelativePoint - m_ColPoints[i].m_PointRelativeToThis;
                m_ControlledCollider.GetCapsuleTransform().Move(-relativeDifference);
            }
            m_ControlledCollider.UpdateContextInfo();
        }
        m_PreviousAmountOfColPoints = m_ColPoints.Count;
        //Clear ColPoints
        for (int i = 0; i < m_ColPoints.Count; i++)
        {
            Destroy(m_ColPoints[i].m_Transform.gameObject);
        }
        m_ColPoints.Clear();
    }