Пример #1
0
    private void UpdateMovePos()
    {
        var delta = Time.deltaTime;

        if (InMoveToTarget)
        {
            _currPos = Vector3.MoveTowards(_currPos, _moveTarget, delta * _moveSpeed);
            Rigid2D.MovePosition(_currPos);

            if (MathUtility.DistanceXY(_currPos, _moveTarget) < 0.5f)
            {
                StopMove();
            }
        }
        else if (InMove)
        {
            _totalFrame += 1;

            //螺旋移动
            if (_moveData.HelixToward != MoveData.EHelixToward.None)
            {
                var eulurZ = (int)_moveData.HelixToward * _moveData.EulurPerFrame * delta * 60f;
                _moveData.Forward = Quaternion.Euler(0, 0, eulurZ) * _moveData.Forward;

                if (_totalFrame - _lastHelixFrame >= _moveData.HelixRefretFrame)
                {
                    _lastHelixFrame       = _totalFrame;
                    _moveData.HelixToward = _moveData.HelixToward == MoveData.EHelixToward.Right ?
                                            MoveData.EHelixToward.Left :
                                            MoveData.EHelixToward.Right;
                }
            }
            Rigid2D.MovePosition(transform.position + _moveData.Forward.normalized * delta * _moveSpeed);
        }
    }
Пример #2
0
        public void Jump(float acceleration)
        {
            if (IsJumping)
            {
                return;
            }

            IsJumping = true;

            Rigid2D.velocity = Vector2.zero;
            var direction = (m_head.position - transform.position).normalized;
            var force     = (direction * acceleration);

            Rigid2D.AddForce(force, ForceMode2D.Impulse);
        }
Пример #3
0
    //移动
    private void Move(Vector3 dir)
    {
        var moveSpeed = InSlow ? Deploy.slowSpeed : Deploy.speed;
        var targetPos = transform.position + dir * Time.fixedDeltaTime * moveSpeed;

        Rigid2D.MovePosition(targetPos);

        if (MathUtility.FloatEqual(dir.x, 0))
        {
            AniStyle = PlayerMoveStyle.Idle;
            return;
        }

        if (dir.x > 0 && AniStyle != PlayerMoveStyle.RightIdle)
        {
            AniStyle = PlayerMoveStyle.RightMove;
        }

        if (dir.x < 0 && AniStyle != PlayerMoveStyle.LeftIdle)
        {
            AniStyle = PlayerMoveStyle.LeftMove;
        }
    }