Ejemplo n.º 1
0
    public virtual void DeformSmooth(Vector3 deformLocation, int direction)
    {
        var deformDirection = deformLocation - transform.position;

        foreach (var vertexId in _originalVertices)
        {
            var vertexPosition  = _vertexManager.GetPosition(vertexId);
            var vertexDirection = vertexPosition - transform.position;

            if (Vector3.Dot(deformDirection, vertexDirection) < 0)
            {
                continue;
            }

            var distanceFromDeformPoint = (vertexPosition - deformLocation).sqrMagnitude;

            if ((Mathf.Sign(direction) == 1 && deformDirection.magnitude > _water.Radius * 2) ||
                (Mathf.Sign(direction) == -1 && deformDirection.magnitude < _water.Radius * 2 / 3))
            {
                continue;
            }

            var force = direction * (DeformSize - distanceFromDeformPoint * distanceFromDeformPoint);

            if (force * direction < 0)
            {
                continue;
            }

            var velocity = deformDirection.normalized * force * _deformSpeed;
            //velocity *= 1f - 10 * Time.deltaTime;

            var newPos = vertexPosition + velocity;

            if (!_deformedVertices.ContainsKey(vertexId))
            {
                _deformedVertices.Add(vertexId, newPos);
            }
            else
            {
                _deformedVertices[vertexId] = newPos;
            }

            _vertexManager.UpdateVertex(vertexId, newPos);
        }
    }