예제 #1
0
        private void DrawCurve(RippleDeformer ripple)
        {
            using (new Handles.DrawingScope(Matrix4x4.TRS(ripple.Axis.position, ripple.Axis.rotation, ripple.Axis.lossyScale)))
            {
                var lineStart     = Vector3.up * -ripple.OuterRadius;
                var lineEnd       = Vector3.up * ripple.OuterRadius;
                var previousPoint = RipplePoint(ripple, lineStart, ripple.Mode == BoundsMode.Limited);
                DeformHandles.Line(Vector3.up * -ripple.OuterRadius, previousPoint, DeformHandles.LineMode.LightDotted);

                for (int i = 0; i <= CURVE_RES; i++)
                {
                    var point = Vector3.Lerp(lineStart, lineEnd, (float)i / CURVE_RES);

                    point = RipplePoint(ripple, point, ripple.Mode == BoundsMode.Limited);

                    DeformHandles.Line(previousPoint, point, DeformHandles.LineMode.Light);

                    previousPoint = point;
                }

                var outerPoint = RipplePoint(ripple, Vector3.up * ripple.OuterRadius, ripple.Mode == BoundsMode.Limited);
//				DeformHandles.Line (previousPoint, outerPoint, DeformHandles.LineMode.Light);
                DeformHandles.Line(lineEnd, outerPoint, DeformHandles.LineMode.LightDotted);
                DeformHandles.Line(lineStart, lineEnd, DeformHandles.LineMode.LightDotted);
            }
        }
예제 #2
0
        private void DrawMagnitudeHandle(RippleDeformer ripple)
        {
            var direction = Vector3.forward;
            var position  = direction * ripple.Amplitude;

            using (var check = new EditorGUI.ChangeCheckScope())
            {
                using (new Handles.DrawingScope(Matrix4x4.TRS(ripple.Axis.position, ripple.Axis.rotation, ripple.Axis.lossyScale)))
                {
                    var newPosition = DeformHandles.Slider(position, direction);
                    if (check.changed)
                    {
                        Undo.RecordObject(ripple, "Changed Magnitude");
                        ripple.Amplitude = newPosition.z;
                    }

                    DeformHandles.Line(Vector3.zero, newPosition, DeformHandles.LineMode.LightDotted);
                }
            }
        }
예제 #3
0
        private Vector3 RipplePoint(RippleDeformer ripple, Vector3 point, bool limited)
        {
            if (ripple.Frequency == 0f)
            {
                return(point);
            }

            var d = new Vector2(point.x, point.y).magnitude;

            if (limited)
            {
                var range = ripple.OuterRadius - ripple.InnerRadius;

                var clampedD = Mathf.Clamp(d, ripple.InnerRadius, ripple.OuterRadius);

                var positionOffset = Mathf.Sin((-ripple.GetTotalOffset() + clampedD * ripple.Frequency) * (float)Mathf.PI * 2f) * ripple.Amplitude;
                if (range != 0f)
                {
                    var pointBetweenBounds = Mathf.Clamp((clampedD - ripple.InnerRadius) / range, 0f, 1f);
                    point.z += Mathf.Lerp(positionOffset, 0f, pointBetweenBounds * ripple.Falloff);
                }
                else
                {
                    if (d > ripple.OuterRadius)
                    {
                        point.z += Mathf.Lerp(positionOffset, 0f, ripple.Falloff);
                    }
                    else if (d < ripple.InnerRadius)
                    {
                        point.z += positionOffset;
                    }
                }
            }
            else
            {
                point.z += Mathf.Sin((ripple.GetTotalOffset() + d * ripple.Frequency) * (float)Mathf.PI * 2f) * ripple.Amplitude;
            }

            return(point);
        }
예제 #4
0
    private void handleInput()
    {
        Ray        inputRay = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (Physics.Raycast(inputRay, out hit))
        {
            //MeshDeformer deformer = hit.collider.GetComponent<MeshDeformer>();
            //if (deformer && deformer.isActiveAndEnabled)
            //{
            //    Vector3 point = hit.point;
            //    point += hit.normal * forceOffset;
            //    deformer.addDeformingForce(point, force);
            //}

            RippleDeformer ripple = hit.collider.GetComponent <RippleDeformer>();
            if (ripple)
            {
                ripple.hitMesh(hit);
            }
        }
    }
예제 #5
0
 void Start()
 {
     ripple = GetComponentInChildren <RippleDeformer>();
 }
예제 #6
0
파일: Enemy.cs 프로젝트: vector8/Sumonami
    void CheckGroundStatus()
    {
        RaycastHit hitInfo;

#if UNITY_EDITOR
        // helper to visualise the ground check ray in the scene view
        Debug.DrawLine(transform.position + (Vector3.up * 0.1f), transform.position + (Vector3.up * 0.1f) + (Vector3.down * m_GroundCheckDistance));
#endif
        // 0.1f is a small offset to start the ray from inside the character
        // it is also good to note that the transform position in the sample assets is at the base of the character

        if (m_IsGrounded && currentRippleSurface != null)
        {
            if (currentRippleSurface.isPositionOnRippleSurface(transform.position))
            {
                // Sample the height of the ripple surface
                float height = currentRippleSurface.sampleMeshHeight(transform.position);

                // Set our y position to the ripple surface height
                Vector3 pos = transform.position;
                pos.y = height + yOffset;
                transform.position = pos;
                m_rb.useGravity    = false;

                // if height is greater than knockup threshold, knock the character into the air
                if (height - currentRippleSurface.transform.position.y > knockupThreshold)
                {
                    m_rb.velocity = new Vector3(m_rb.velocity.x, knockupPower, m_rb.velocity.z);
                    m_IsGrounded  = false;
                    //m_Animator.applyRootMotion = false;
                    m_GroundCheckDistance = 0.1f;
                    m_rb.useGravity       = true;
                }
            }
            else
            {
                // We are no longer in the bounds of the ripple surface, set us to not be grounded so we can check if there is anything under us.
                currentRippleSurface = null;
                m_IsGrounded         = false;
                m_GroundNormal       = Vector3.up;
                //m_Animator.applyRootMotion = false;
                m_rb.useGravity = true;
            }
        }
        else if (!m_IsGrounded)
        {
            if (Physics.Raycast(transform.position + (Vector3.up * 0.1f), Vector3.down, out hitInfo))
            {
                RippleDeformer ripple = hitInfo.collider.GetComponent <RippleDeformer>();
                if (ripple)  // We are above a surface that can ripple
                {
                    currentRippleSurface = ripple;
                    // Sample the height of the ripple surface
                    float height           = currentRippleSurface.sampleMeshHeight(hitInfo);
                    float distanceToGround = transform.position.y - yOffset - height;
                    if (distanceToGround > dropDistanceToDie)
                    {
                        willDie = true;
                    }
                    // Check if we can land (we are close to the ground and our velocity is downwards
                    if (distanceToGround <= m_GroundCheckDistance && m_rb.velocity.y <= 0)
                    {
                        // We've hit the ripple surface, die
                        m_GroundNormal = hitInfo.normal;
                        m_IsGrounded   = true;
                        ////m_Animator.applyRootMotion = true;
                        m_rb.useGravity = false;

                        if (willDie)
                        {
                            onDeath();
                        }
                    }
                }
                else    // We are above a surface that cannot ripple
                {
                    if (Vector3.Distance(hitInfo.point, transform.position) < m_GroundCheckDistance)
                    {
                        m_GroundNormal = hitInfo.normal;
                        m_IsGrounded   = true;
                        //m_Animator.applyRootMotion = true;
                    }
                    else
                    {
                        m_IsGrounded   = false;
                        m_GroundNormal = Vector3.up;
                        //m_Animator.applyRootMotion = false;
                    }
                }
            }
        }
    }
예제 #7
0
 void Start()
 {
     deform = GetComponent <RippleDeformer> ();
     // originalTransform = transform;
     originalAmplitude = deform.Amplitude;
 }
예제 #8
0
        void CheckGroundStatus()
        {
            RaycastHit hitInfo;

#if UNITY_EDITOR
            // helper to visualise the ground check ray in the scene view
            Debug.DrawLine(transform.position + (Vector3.up * 0.1f), transform.position + (Vector3.up * 0.1f) + (Vector3.down * m_GroundCheckDistance));
#endif
            // 0.1f is a small offset to start the ray from inside the character
            // it is also good to note that the transform position in the sample assets is at the base of the character

            if (m_IsGrounded && currentRippleSurface != null)
            {
                if (currentRippleSurface.isPositionOnRippleSurface(transform.position))
                {
                    // Sample the height of the ripple surface
                    float height = currentRippleSurface.sampleMeshHeight(transform.position);

                    // Set our y position to the ripple surface height
                    Vector3 pos = transform.position;
                    pos.y = height;
                    transform.position     = pos;
                    m_Rigidbody.useGravity = false;

                    // if height is greater than knockup threshold, knock the character into the air
                    if (!immuneToKnockup && height - currentRippleSurface.transform.position.y > knockupThreshold)
                    {
                        m_Rigidbody.velocity       = new Vector3(m_Rigidbody.velocity.x, m_JumpPower, m_Rigidbody.velocity.z);
                        m_IsGrounded               = false;
                        m_Animator.applyRootMotion = false;
                        m_GroundCheckDistance      = 0.1f;
                        m_Rigidbody.useGravity     = true;
                    }
                }
                else
                {
                    // We are no longer in the bounds of the ripple surface, set us to not be grounded so we can check if there is anything under us.
                    currentRippleSurface       = null;
                    m_IsGrounded               = false;
                    m_GroundNormal             = Vector3.up;
                    m_Animator.applyRootMotion = false;
                    m_Rigidbody.useGravity     = true;
                }
            }
            else if (!m_IsGrounded)
            {
                if (Physics.Raycast(transform.position + (Vector3.up * 0.1f), Vector3.down, out hitInfo))
                {
                    RippleDeformer ripple = hitInfo.collider.GetComponent <RippleDeformer>();
                    if (ripple)  // We are above a surface that can ripple
                    {
                        currentRippleSurface = ripple;
                        // Sample the height of the ripple surface
                        float height = currentRippleSurface.sampleMeshHeight(hitInfo);
                        // Check if we can land (we are close to the ground and our velocity is downwards
                        if (transform.position.y - height <= m_GroundCheckDistance && m_Rigidbody.velocity.y <= 0)
                        {
                            // We've hit the ripple surface, grant us knockup immunity
                            immuneToKnockup          = true;
                            immunityFromKnockupTimer = IMMUNITY_DURATION;
                            // Scale the mesh hit force based on the downward velocity
                            float velocity = -m_Rigidbody.velocity.y;

                            currentRippleSurface.splashDiameter = (int)Mathf.Lerp(5, 15, velocity / 20);
                            currentRippleSurface.hitMesh(hitInfo);

                            m_GroundNormal             = hitInfo.normal;
                            m_IsGrounded               = true;
                            m_Animator.applyRootMotion = true;
                            m_Rigidbody.useGravity     = false;

                            // Instantiate ground smash particles
                            GameObject g = Instantiate <GameObject>(hitGroundParticles);
                            g.transform.position = transform.position;

                            fall.clip = falling;
                            fall.Play();
                        }
                    }
                    else    // We are above a surface that cannot ripple
                    {
                        //if (Vector3.Distance(hitInfo.point, transform.position) < m_GroundCheckDistance)
                        //{
                        //    m_GroundNormal = hitInfo.normal;
                        //    m_IsGrounded = true;
                        //    m_Animator.applyRootMotion = true;
                        //}
                        //else
                        //{
                        //    m_IsGrounded = false;
                        //    m_GroundNormal = Vector3.up;
                        //    m_Animator.applyRootMotion = false;
                        //}
                    }
                }
            }
        }
예제 #9
0
        void CheckGroundStatus()
        {
            RaycastHit hitInfo;

#if UNITY_EDITOR
            // helper to visualise the ground check ray in the scene view
            Debug.DrawLine(transform.position + (Vector3.up * 0.1f), transform.position + (Vector3.up * 0.1f) + (Vector3.down * m_GroundCheckDistance));
#endif
            // 0.1f is a small offset to start the ray from inside the character
            // it is also good to note that the transform position in the sample assets is at the base of the character

            if (m_IsGrounded && currentRippleSurface != null)
            {
                if (currentRippleSurface.isPositionOnRippleSurface(transform.position))
                {
                    // Sample the height of the ripple surface
                    float height = currentRippleSurface.sampleMeshHeight(transform.position);

                    // Set our y position to the ripple surface height
                    Vector3 pos = transform.position;
                    pos.y = height;
                    transform.position     = pos;
                    m_Rigidbody.useGravity = false;
                }
                else
                {
                    // We are no longer in the bounds of the ripple surface, set us to not be grounded so we can check if there is anything under us.
                    currentRippleSurface       = null;
                    m_IsGrounded               = false;
                    m_GroundNormal             = Vector3.up;
                    m_Animator.applyRootMotion = false;
                    m_Rigidbody.useGravity     = true;
                }
            }

            if (!m_IsGrounded)
            {
                if (Physics.Raycast(transform.position + (Vector3.up * 0.1f), Vector3.down, out hitInfo))
                {
                    RippleDeformer ripple = hitInfo.collider.GetComponent <RippleDeformer>();
                    if (ripple)  // We are above a surface that can ripple
                    {
                        currentRippleSurface = ripple;
                        // Sample the height of the ripple surface
                        float height = currentRippleSurface.sampleMeshHeight(hitInfo);
                        // Check if we can land
                        if (transform.position.y - height <= m_GroundCheckDistance)
                        {
                            // We've hit the ripple surface
                            // Scale the mesh hit force based on the downward velocity
                            float velocity = -m_Rigidbody.velocity.y;

                            currentRippleSurface.splashDiameter = (int)Mathf.Lerp(5, 25, velocity / 20);
                            currentRippleSurface.hitMesh(hitInfo);

                            m_GroundNormal             = hitInfo.normal;
                            m_IsGrounded               = true;
                            m_Animator.applyRootMotion = true;
                            m_Rigidbody.useGravity     = false;
                        }
                    }
                    else    // We are above a surface that cannot ripple
                    {
                        if (Vector3.Distance(hitInfo.point, transform.position) < m_GroundCheckDistance)
                        {
                            m_GroundNormal             = hitInfo.normal;
                            m_IsGrounded               = true;
                            m_Animator.applyRootMotion = true;
                        }
                        else
                        {
                            m_IsGrounded               = false;
                            m_GroundNormal             = Vector3.up;
                            m_Animator.applyRootMotion = false;
                        }
                    }
                }
            }
        }