예제 #1
0
파일: PlayerMover.cs 프로젝트: zamp/PuckMan
    // Update is called once per frame
    void Update()
    {
        Vector2 newDir = new Vector2(
            Input.GetAxisRaw("Horizontal"),
            Input.GetAxisRaw("Vertical")
            );

        if (newDir.SqrMagnitude() < 0.05f)
        {
            // The input is REALLY small (probably zero),
            // so don't change the desired direction
            return;
        }

        // newDir could be REALLY wonky at this point. Could be diagonal,
        // could have a fractional number like (0.67, -0.24)

        // In case we have both an X and a Y
        if (Mathf.Abs(newDir.x) >= Mathf.Abs(newDir.y))
        {
            // X is bigger, so zero the Y
            newDir.y = 0;
        }
        else
        {
            newDir.x = 0;
        }

        mazeMover.SetDesiredDirection(newDir.normalized, true);
    }
예제 #2
0
    void DoTurn()
    {
        // Do a turn to the "left" or "right"

        Vector2 newDir = Vector2.zero;

        Vector2 oldDir = mazeMover.GetDesiredDirection();

        if (Mathf.Abs(oldDir.x) > 0)
        {
            // Moving left-right currently.
            // A "smarter" enemy might ask: Is the player above or below us, and
            // weight the "Y" direction accordingly
            newDir.y = Random.Range(0, 2) == 0 ? -1 : 1;
        }
        else
        {
            // Currently moving up-down
            newDir.x = Random.Range(0, 2) == 0 ? -1 : 1;
        }

        mazeMover.SetDesiredDirection(newDir);
    }