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; }
void jump() { Vector3 gravityDir = GravityManager.Instance().gravityDir; rbody.AddForce(gravityDir * -jumpImpulse, ForceMode.Impulse); //playerState = PlayerState.Jump; TimeManager.Instance().timeDictionary["jumpDelay"] = jumpDelay; }
void FixedUpdate() { GravityManager manager = GravityManager.Instance(); if (manager != null) { rbody.AddForce(manager.gravityDir * manager.gravityMagnitude); } }
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(); }
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); } } }
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(); } } }