Exemple #1
0
        private void LateUpdate()
        {
            if (m_fluid)
            {
                Vector3 currentPosition = transform.position;
                if (m_speed != Vector3.zero)
                {
                    if (m_tempCol == null)
                    {
                        m_tempCol = m_fluid.GetComponent <Collider>();
                    }
                    if (m_tempRend == null)
                    {
                        m_tempRend = m_fluid.GetComponent <Renderer>();
                    }

                    ray = new Ray(currentPosition, Vector3.forward);
                    if (m_tempCol.Raycast(ray, out hitInfo, 10))
                    {
                        fWidth  = m_tempRend.bounds.extents.x * 2f;
                        fRadius = (GetRadius() * m_fluid.GetWidth()) / fWidth;
                        m_fluid.AddVelocity(hitInfo.textureCoord, -m_speed, fRadius);
                    }
                }
            }
        }
Exemple #2
0
 void LateUpdate()
 {
     ray = new Ray(transform.position, Vector3.forward);
     if (m_tempCol.Raycast(ray, out hitInfo, 10))
     {
         fWidth  = m_tempRend.bounds.extents.x * 2f;
         fRadius = (GetRadius() * m_FluidSimulator.GetWidth()) / fWidth;
         m_FluidSimulator.AddObstacleCircle(hitInfo.textureCoord, fRadius, false);
     }
 }
Exemple #3
0
 private void LateUpdate()
 {
     for (int i = 0; i < Input.touchCount; ++i)
     {
         touch = Input.GetTouch(i);
         ray   = Camera.main.ScreenPointToRay(new Vector3(touch.position.x, touch.position.y, 0f));
         if (m_tempCol.Raycast(ray, out hitInfo, 100))
         {
             fWidth  = m_tempRend.bounds.extents.x * 2f;
             fRadius = (m_particlesRadius * m_fluid.GetParticlesWidth()) / fWidth;
             m_fluid.AddParticles(hitInfo.textureCoord, fRadius, m_particlesStrength * Time.deltaTime);
             if (touch.phase == TouchPhase.Moved)
             {
                 direction = new Vector3(touch.deltaPosition.x, touch.deltaPosition.y) * m_velocityStrength * touch.deltaTime;
                 fWidth    = m_tempRend1.bounds.extents.x * 2f;
                 fRadius   = (m_velocityRadius * m_fluid.GetWidth()) / fWidth;
                 m_fluid.AddVelocity(hitInfo.textureCoord, direction, fRadius);
             }
         }
     }
 }
Exemple #4
0
        private void ManipulateParticles()
        {
            if (Input.GetMouseButton(0) || m_alwaysOn)
            {
                Debug.Log("0");
                m_mousePos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0f);
                ray        = Camera.main.ScreenPointToRay(m_mousePos);
                if (m_tempCol.Raycast(ray, out hitInfo, 100))
                {
                    fWidth  = m_tempRend.bounds.extents.x * 2f;
                    fRadius = (m_particlesRadius * m_fluid.GetParticlesWidth()) / fWidth;
                    m_fluid.AddParticles(hitInfo.textureCoord, fRadius, m_particlesStrength * Time.deltaTime);
                }
            }
            if (Input.GetMouseButton(1) || m_alwaysOn)
            {
                Debug.Log("1");
                m_mousePos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0f);
                ray        = Camera.main.ScreenPointToRay(m_mousePos);
                if (m_tempCol.Raycast(ray, out hitInfo, 100))
                {
                    Debug.Log("1 - raycast");
                    direction = new Vector3(1.0f, 0.0f, 0.0f);
                    direction = direction * m_velocityStrength * Time.deltaTime;
                    fWidth    = m_tempRend.bounds.extents.x * 2f;
                    fRadius   = (m_velocityRadius * m_fluid.GetWidth()) / fWidth;

                    if (Input.GetMouseButton(0))
                    {
                        Debug.Log("1 - added velocity");
                        m_fluid.AddVelocity(hitInfo.textureCoord, -direction, fRadius);
                        Debug.Log(direction);
                    }
                    else
                    {
                        m_fluid.AddVelocity(hitInfo.textureCoord, direction, fRadius);
                    }
                }
            }
        }
 private void UpdatePosition()
 {
     if (m_fluid)
     {
         ray = new Ray(gameObject.transform.position, Vector3.forward);
         if (m_tempCol.Raycast(ray, out m_HitInfo, distance))
         {
             m_FluidSSize           = new Vector2(m_fluid.GetWidth(), m_fluid.GetHeight());
             m_PosInFluidSpace      = new Vector2(m_HitInfo.textureCoord.x * m_FluidSSize.x, m_HitInfo.textureCoord.y * m_FluidSSize.y);
             m_velocityInFluidSpace = m_fluid.GetVelocity((int)m_PosInFluidSpace.x, (int)m_PosInFluidSpace.y) * Time.deltaTime;
             m_WorldVelocity        = new Vector2((m_velocityInFluidSpace.x * m_fluid.GetRenderSize().x) / m_FluidSSize.x, (m_velocityInFluidSpace.y * m_fluid.GetRenderSize().y) / m_FluidSSize.y);
             if (!useRigidbody)
             {
                 transform.position += Vector3.Lerp(transform.position, m_WorldVelocity, lerpSpeed) * Time.deltaTime / m_Weight;
             }
             else
             {
                 rig.velocity += Vector2.Lerp(transform.position, m_WorldVelocity, lerpSpeed) * Time.deltaTime / m_Weight;
             }
         }
     }
 }