Exemplo n.º 1
0
    public void MoveDirection(movementDirection e)
    {
        if (isDummy)
        {
            return;
        }
        Quaternion targetRotation = transform.rotation;

        switch (e)
        {
        case movementDirection.Forward:
            direction     += new Vector3(0.0f, 0.0f, 2.0f);
            targetRotation = Quaternion.Euler(0, 0, 0);
            break;

        case movementDirection.Backward:
            direction     += new Vector3(0.0f, 0.0f, -2.0f);
            targetRotation = Quaternion.Euler(0, -180, 0);
            break;

        case movementDirection.Left:
            direction     += new Vector3(-2.0f, 0.0f, 0.0f);
            targetRotation = Quaternion.Euler(0, -90, 0);
            break;

        case movementDirection.Right:
            direction     += new Vector3(2.0f, 0.0f, 0.0f);
            targetRotation = Quaternion.Euler(0, 90, 0);
            break;

        default:
            break;
        }
        transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, .4f);
    }
Exemplo n.º 2
0
 public void setDirection(movementDirection newDirection)
 {
     if (direction != newDirection)
     {
         direction = newDirection;
     }
 }
Exemplo n.º 3
0
    void SetAnimation(movementDirection dir)
    {
        if (dir == movementDirection.idle)
        {
            if (animator.GetInteger("AnimState") == 0)
            {
                return;
            }
            animator.SetInteger("IdleDir", animator.GetInteger("AnimState"));
            animator.SetInteger("AnimState", 0);
        }

        if (dir == movementDirection.up)
        {
            animator.SetInteger("AnimState", 1);
        }

        if (dir == movementDirection.down)
        {
            animator.SetInteger("AnimState", 2);
        }


        if (dir == movementDirection.right)
        {
            animator.SetInteger("AnimState", 3);
        }

        if (dir == movementDirection.left)
        {
            animator.SetInteger("AnimState", 4);
        }
    }
Exemplo n.º 4
0
    void InputMovementDirection()
    {
        currentDirection = movementDirection.idle;


        if (Input.GetKey(KeyCode.D))
        {
            currentDirection = movementDirection.right;
            moveAmount.x    += 1;
        }
        if (Input.GetKey(KeyCode.A))
        {
            currentDirection = movementDirection.left;
            moveAmount.x    -= 1;
        }
        if (Input.GetKey(KeyCode.W))
        {
            currentDirection = movementDirection.up;
            moveAmount.y    += 1;
        }
        if (Input.GetKey(KeyCode.S))
        {
            currentDirection = movementDirection.down;
            moveAmount.y    -= 1;
        }
    }
Exemplo n.º 5
0
    void GoToNextNode()
    {
        transform.position = grid.NodeWorldPos(nextNode);

        lastNode    = currentNode;
        currentNode = nextNode;
        nextNode    = parentTailScript.currentNode;


        RotateBasedOnDirection(nextDirection);

        lastDirection    = currentDirection;
        currentDirection = nextDirection;
        nextDirection    = parentTailScript.currentDirection;
    }
Exemplo n.º 6
0
    void GoToNextNodeBeingHead()
    {
        // Last node TRACKER
        lastNode = currentNode;

        // Get Next Node
        currentNode = grid.GetNodeFromWorldPoint(transform.position + VectorFromDirection());


        // Do Movement
        transform.position = grid.NodeWorldPos(currentNode);

        // Last direction TRACKER
        lastDirection = currentDirection;
    }
Exemplo n.º 7
0
 void RotateBasedOnDirection(movementDirection currentDirection)
 {
     if (currentDirection == movementDirection.front)
     {
         transform.rotation = Quaternion.Euler(Vector3.forward * 0);
     }
     else if (currentDirection == movementDirection.back)
     {
         transform.rotation = Quaternion.Euler(Vector3.forward * 180);
     }
     else if (currentDirection == movementDirection.right)
     {
         transform.rotation = Quaternion.Euler(Vector3.forward * -90);
     }
     else if (currentDirection == movementDirection.left)
     {
         transform.rotation = Quaternion.Euler(Vector3.forward * 90);
     }
 }
Exemplo n.º 8
0
    movementDirection FindCurrentDirection()
    {
        movementDirection currentDirection = movementDirection.front;

        if (transform.rotation.eulerAngles.z == 0f)
        {
            currentDirection = movementDirection.front;
        }
        else if (transform.rotation.eulerAngles.z == 90f)
        {
            currentDirection = movementDirection.left;
        }
        else if (transform.rotation.eulerAngles.z == 180f)
        {
            currentDirection = movementDirection.back;
        }
        else if (transform.rotation.eulerAngles.z == -90f)
        {
            currentDirection = movementDirection.right;
        }

        return(currentDirection);
    }
Exemplo n.º 9
0
    public Quaternion RotationFromDirection(movementDirection direction)
    {
        Quaternion rotation = new Quaternion(0, 0, 0, 0);

        if (currentDirection == movementDirection.front)
        {
            rotation = Quaternion.Euler(Vector3.forward * 0);
        }
        else if (currentDirection == movementDirection.back)
        {
            rotation = Quaternion.Euler(Vector3.forward * 180);
        }
        else if (currentDirection == movementDirection.right)
        {
            rotation = Quaternion.Euler(Vector3.forward * -90);
        }
        else if (currentDirection == movementDirection.left)
        {
            rotation = Quaternion.Euler(Vector3.forward * 90);
        }

        return(rotation);
    }
Exemplo n.º 10
0
        /// <summary>
        /// Moves Center by moveChange in specified direction (absolute in world coordinates)
        /// Movement is alligned with absolute world coodinates and current position of camera does not matter
        /// Direction.Reset sets Center to origin (0, 0, 0)
        /// </summary>
        /// <param name="movementDirection">Direction to move Center to</param>
        private void MoveCenterByAxes(movementDirection movementDirection)
        {
            Vector3 movement = Vector3.Zero;

            switch (movementDirection)
            {
            case movementDirection.Left:
                movement.X = -moveChange;
                break;

            case movementDirection.Right:
                movement.X = moveChange;
                break;

            case movementDirection.Forward:
                movement.Z = -moveChange;
                break;

            case movementDirection.Backwards:
                movement.Z = moveChange;
                break;

            case movementDirection.Up:
                movement.Y = moveChange;
                break;

            case movementDirection.Down:
                movement.Y = -moveChange;
                break;

            case movementDirection.Reset:
                Center = Vector3.Zero;
                break;
            }

            Center = Center + movement;
        }
Exemplo n.º 11
0
        /// <summary>
        /// Moves Center by moveChange in specified direction (absolute in world coordinates)
        /// Movement is relative to current camera direction (Eye - Center)
        /// Direction.Reset sets Center to origin (0, 0, 0)
        /// </summary>
        /// <param name="movementDirection">Direction to move Center to</param>
        private void MoveCenter(movementDirection movementDirection)
        {
            Vector3 movement = Vector3.Zero;

            switch (movementDirection)
            {
            case movementDirection.Left:
                movement += Right * moveFactor;
                break;

            case movementDirection.Right:
                movement -= Right * moveFactor;
                break;

            case movementDirection.Forward:
                movement += Direction * moveFactor;
                break;

            case movementDirection.Backwards:
                movement -= Direction * moveFactor;
                break;

            case movementDirection.Up:
                movement += Up * moveFactor;
                break;

            case movementDirection.Down:
                movement -= Up * moveFactor;
                break;

            case movementDirection.Reset:
                Center = Vector3.Zero;
                break;
            }

            Center += movement;
        }