예제 #1
0
    void Update()
    {
        if (followObject == null || followObject.activeSelf == false)
        {
            if (GameContext.player != null)
            {
                followObject = GameContext.player.gameObject;
            }
            else
            {
                return;
            }
        }
        Transform follow     = followObject.transform;
        Vector3   gravityDir = GravityManager.Instance().gravityDir;
        float     degree     = Vector3.Angle(Vector3.down, gravityDir);

        if (gravityDir.x < 0)
        {
            degree = -degree;
        }
        transform.rotation = Quaternion.Euler(0, 0, degree);
        //transform.LookAt(follow, -GravityManager.Instance().gravityDir);
        //transform.forward = follow.position - transform.position;
        //transform.up = -GravityManager.Instance().gravityDir;
        transform.position = follow.position + cameraOffset;
    }
예제 #2
0
    void jump()
    {
        Vector3 gravityDir = GravityManager.Instance().gravityDir;

        rbody.AddForce(gravityDir * -jumpImpulse, ForceMode.Impulse);
        //playerState = PlayerState.Jump;
        TimeManager.Instance().timeDictionary["jumpDelay"] = jumpDelay;
    }
예제 #3
0
    void FixedUpdate()
    {
        GravityManager manager = GravityManager.Instance();

        if (manager != null)
        {
            rbody.AddForce(manager.gravityDir * manager.gravityMagnitude);
        }
    }
예제 #4
0
    void Update()
    {
        Vector3 gravityDir = GravityManager.Instance().gravityDir;
        float   degree     = Vector3.Angle(Vector3.down, gravityDir);

        if (gravityDir.x < 0)
        {
            degree = -degree;
        }
        transform.rotation = Quaternion.Euler(0, 0, degree);
        HandleInput();
    }
예제 #5
0
    void walkLeftRight()
    {
        bool    getA = Input.GetKey(KeyCode.A), getD = Input.GetKey(KeyCode.D);
        Vector3 gravityDir = GravityManager.Instance().gravityDir;

        //if not pressing both
        if (getA != getD)
        {
            if (getA)
            {
                rbody.AddForce(Vector3.Cross(gravityDir, Vector3.forward) * walkForce);
            }
            else
            {
                rbody.AddForce(Vector3.Cross(gravityDir, Vector3.forward) * -walkForce);
            }
        }
    }
예제 #6
0
 void HandleInput()
 {
     if (PlayerState.Jump == playerState)
     {
         walkLeftRight();
         if (GetJumpKey() && TimeManager.Instance().timeDictionary.ContainsKey("jumpDelay"))
         {
             Vector3 gravityDir = GravityManager.Instance().gravityDir;
             rbody.AddForce(gravityDir * -jumpForce);
         }
     }
     else if (PlayerState.Walk == playerState)
     {
         walkLeftRight();
         if (GetJumpKeyDown())
         {
             jump();
         }
     }
 }