コード例 #1
0
        private void Update()
        {
            if (_dragging)
            {
                _currentVelocity = -_lastDragDelta;
                _dragSpeedAverage.AddSample(_currentVelocity);
            }
            else
            {
                var currentSpeed = _currentVelocity.magnitude;
                if (currentSpeed > _slideStopThreshold / _screenToCanvasScaleFactor)
                {
                    _currentVelocity = Vector3.MoveTowards(_currentVelocity, Vector3.zero,
                                                           _slideDecelerationFactor * currentSpeed * Time.deltaTime);
                }
                else
                {
                    _currentVelocity = Vector2.zero;
                }
            }

            if (_currentVelocity.magnitude > 0.01f)
            {
                Vector3 worldspaceDelta = _currentVelocity * _screenToWorldScaleFactor;
                var     newPosition     = _camera.transform.position += worldspaceDelta;
                newPosition.x = 0f;
                newPosition.y = Mathf.Clamp(newPosition.y, _bottomLimit, _topLimit);
                _camera.transform.position = newPosition;
            }

            _lastDragDelta = Vector2.zero;
        }
コード例 #2
0
ファイル: Ball.cs プロジェクト: disas69/Splashy-Colors
        private void Update()
        {
            if (!_isActive)
            {
                return;
            }

            var newPosition = transform.position;

            _dragSpeedAverage.AddSample(_dragging ? _lastDragDelta : Vector2.zero);
            var velocity = _dragSpeedAverage.Value;

            if (velocity.magnitude > 0.01f)
            {
                var worldSpaceDelta = velocity * GameConfiguration.Instance.BallSettings.MoveSpeed * _screenToWorldScaleFactor;
                newPosition = Vector3.SmoothDamp(transform.position, transform.position + worldSpaceDelta, ref _velocity, GameConfiguration.Instance.BallSettings.SmoothSpeed);
            }

            _lastDragDelta = Vector2.zero;

            var nextPathLine = GetNextPathLine();

            if (nextPathLine != null)
            {
                var distance = Mathf.Abs(transform.position.z - nextPathLine.Position.z);
                var halfWay  = GetHalfWay(nextPathLine);

                if (distance > halfWay)
                {
                    distance     -= halfWay;
                    newPosition.y = Mathf.Lerp(GameConfiguration.Instance.BallSettings.JumpHeight, 0f, GameConfiguration.Instance.BallSettings.InCurve.Evaluate(distance / halfWay));
                }
                else
                {
                    newPosition.y = Mathf.Lerp(0f, GameConfiguration.Instance.BallSettings.JumpHeight, GameConfiguration.Instance.BallSettings.OutCurve.Evaluate(distance / halfWay));
                }
            }

            transform.position = new Vector3(Mathf.Clamp(newPosition.x, -GameConfiguration.Instance.BallSettings.XPositionCap, GameConfiguration.Instance.BallSettings.XPositionCap),
                                             Mathf.Clamp(newPosition.y, 0f, GameConfiguration.Instance.BallSettings.JumpHeight), newPosition.z);
        }
コード例 #3
0
ファイル: PlayerInputHandler.cs プロジェクト: disas69/Pong
        private void Update()
        {
            if (_isDragging)
            {
                _currentVelocity = _lastDragDelta;
                _dragSpeedAverager.AddSample(_currentVelocity);
            }
            else
            {
                var currentSpeed = _currentVelocity.magnitude;
                if (currentSpeed > _slideStopThreshold / _screenToCanvasScaleFactor)
                {
                    _currentVelocity = Vector3.MoveTowards(_currentVelocity, Vector3.zero, _slideDecelerationFactor * currentSpeed * Time.deltaTime);
                }
                else
                {
                    _currentVelocity = Vector2.zero;
                }
            }

            UpdatePositions(_currentVelocity * _screenToWorldScaleFactor);
            _lastDragDelta = Vector2.zero;
        }
コード例 #4
0
ファイル: InputHandler.cs プロジェクト: disas69/Triangle
 public void Update()
 {
     _dragSpeedAverage.AddSample(_lastDragDelta);
     _lastDragDelta = DeselerateDragDelta(_dragSpeedAverage.Value);
 }