Exemple #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);
    }
 public void setDirection(movementDirection newDirection)
 {
     if (direction != newDirection)
     {
         direction = newDirection;
     }
 }
    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);
        }
    }
    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;
        }
    }
Exemple #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;
    }
Exemple #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;
    }
Exemple #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);
     }
 }
Exemple #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);
    }
Exemple #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);
    }
Exemple #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;
        }
Exemple #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;
        }