Exemplo n.º 1
0
    public void Update()
    {
        if (isMoving == false)
        {
            if (movingTo == MovingTo.UP)
            {
                movingTo          = MovingTo.DOWN;
                movingToTransform = new Vector2(gameObject.transform.position.x, gameObject.transform.position.y - (wonderAmount / 2));
                isMoving          = true;
            }
            else
            {
                movingTo          = MovingTo.UP;
                movingToTransform = new Vector2(gameObject.transform.position.x, gameObject.transform.position.y + (wonderAmount / 2));
                isMoving          = true;
            }
        }

        gameObject.transform.position = Vector2.MoveTowards(gameObject.transform.position, movingToTransform, movementSpeed * Time.deltaTime);

        if ((Vector2)gameObject.transform.position == movingToTransform)
        {
            isMoving = false;
        }
    }
Exemplo n.º 2
0
 public void MoveSmoothToPlayer()
 {
     timeElapsed    = 0;
     startPositionX = transform.position.x;
     endPositionX   = target.position.x;
     moveTime       = camereMoveToPlayerTime;
     movingTo       = MovingTo.Player;
     moveSmooth     = true;
 }
    void Start()
    {
        target            = MovingTo.toPosition1;
        platform.position = position1.position;
        initialPosition   = position1.position;
        timer             = resetTime;

        ChangeTarget();
    }
Exemplo n.º 4
0
 public void MoveSmoothToObstacle(float targetX)
 {
     FindObjectOfType <PlayerMovement>().freezeMovement = true;
     startPositionX = transform.position.x + distanceToEgde;
     endPositionX   = targetX;
     timeElapsed    = 0;
     moveTime       = cameraMoveToEnemyTime;
     movingTo       = MovingTo.Enemy;
     moveSmooth     = true;
 }
Exemplo n.º 5
0
 private void Awake()
 {
     _previousTransform = new TransformStorage
     {
         Position   = transform.position,
         Rotation   = transform.rotation,
         LocalScale = transform.localScale
     };
     CurrentStatus = Status.Idle;
     MoveDirection = MovingTo.None;
     // refresh status at frequency
     InvokeRepeating("RefreshStatus", RefreshStatusFrequency,
                     RefreshStatusFrequency);
 }
    void ChangeTarget()
    {
        if (target == MovingTo.toPosition1)
        {
            target          = MovingTo.toPosition2;
            initialPosition = position1.position;
            targetPosition  = position2.position;
        }
        else
        {
            target          = MovingTo.toPosition1;
            initialPosition = position2.position;
            targetPosition  = position1.position;
        }

        lerpCounter = 0.0f;
    }
Exemplo n.º 7
0
        private void RefreshStatus()
        {
            var positionDistance = UseSquareDistance
                ? Vector3.SqrMagnitude(transform.position -
                                       _previousTransform.Position)
                : Vector3.Distance(transform.position,
                                   _previousTransform.Position);
            var turningAngle = Quaternion.Angle(transform.rotation,
                                                _previousTransform.Rotation);
            var movingDirection =
                (transform.position - _previousTransform.Position).normalized;

            // detect if actor moved
            CurrentStatus = positionDistance > PositionChangeTolerance
                ? Status.Moving
                : Status.Idle;
            // detect if actor turned
            CurrentStatus |= turningAngle > TurningDistanceTolerance
                ? Status.Turning
                : CurrentStatus;

            var downDirection = transform.TransformDirection(Vector3.down);
            var leftDirection = transform.TransformDirection(Vector3.left);
            var backDirection = transform.TransformDirection(Vector3.back);

            MoveDirection = MovingTo.None;
            // moving up or down

            if ((!UseSquareDistance
                ? Vector3.Distance(movingDirection, transform.up)
                : Vector3.SqrMagnitude(movingDirection - transform.up)) <=
                TurningDistanceTolerance)
            {
                MoveDirection = MovingTo.Up;
            }
            else if ((!UseSquareDistance
                ? Vector3.Distance(movingDirection, downDirection)
                : Vector3.SqrMagnitude(movingDirection - downDirection)) <=
                     TurningDistanceTolerance)
            {
                MoveDirection = MovingTo.Down;
            }
            // moving right of left
            if ((!UseSquareDistance
                ? Vector3.Angle(movingDirection, transform.right)
                : Vector3.SqrMagnitude(movingDirection - transform.right)) <=
                TurningDistanceTolerance)
            {
                MoveDirection = MoveDirection | MovingTo.Right;
            }
            else if ((!UseSquareDistance
                ? Vector3.Distance(movingDirection, leftDirection)
                : Vector3.SqrMagnitude(movingDirection - leftDirection)) <=
                     TurningDistanceTolerance)
            {
                MoveDirection = MoveDirection | MovingTo.Left;
            }
            // moving forward or backwards
            if ((!UseSquareDistance
                ? Vector3.Distance(movingDirection, transform.forward)
                : Vector3.SqrMagnitude(movingDirection - transform.forward)) <=
                TurningDistanceTolerance)
            {
                MoveDirection = MoveDirection | MovingTo.Forward;
            }
            else if ((!UseSquareDistance
                ? Vector3.Distance(movingDirection, backDirection)
                : Vector3.SqrMagnitude(movingDirection - backDirection)) <=
                     TurningDistanceTolerance)
            {
                MoveDirection = MoveDirection | MovingTo.Backwards;
            }
            // if actually moving delete None flag
            if ((MoveDirection & ~MovingTo.None) > 0)
            {
                MoveDirection = MoveDirection & ~MovingTo.None;
            }

            _previousTransform.Position   = transform.position;
            _previousTransform.Rotation   = transform.rotation;
            _previousTransform.LocalScale = transform.localScale;
        }