// Update is called once per frame void Update() { if (count == 2 && Input.GetAxis("Trigger") > 0.2 && RotateSeq.getRightJQ() != 0) { Time.timeScale = 1f; text.SetActive(false); Destroy(this); } }
// Update is called once per frame void Update() { if (count == 2 && RotateSeq.getRightJQ() != 0) { Time.timeScale = 1f; text.SetActive(false); Destroy(this); } }
void FixedUpdate() { Vector3 checkLoc = feet.transform.position + Vector3.down * (feet.radius * 0.2f); prevGrounded = grounded; grounded = (Physics.Raycast(checkLoc + groudCheckOffset, Vector3.down, feet.radius, groundPhysicsLayerMask)) || (Physics.Raycast(checkLoc - groudCheckOffset, Vector3.down, feet.radius, groundPhysicsLayerMask)); //Debug.DrawLine(checkLoc + groudCheckOffset, checkLoc + groudCheckOffset - new Vector3(0, feet.radius, 0), Color.red, 1f); //Debug.DrawLine(checkLoc - groudCheckOffset, checkLoc - groudCheckOffset - new Vector3(0, feet.radius, 0), Color.red, 1f); Vector3 vel = bodyRigid.velocity; //============================ Move ========================== if (getLeftJQ() == 1 || getLeftJQ() == 8) { vel.x = speedH.x; vel.z = speedH.z; } else if (getLeftJQ() == 4 || getLeftJQ() == 5) { vel.x = -speedH.x; vel.z = -speedH.z; } else { vel.x = 0; vel.z = 0; } if (Mathf.Abs(vel.y) < 0.001) { vel.y = 0; } //============================ Jump ========================== //Vector3 up = HammerRigid.gameObject.transform.up; //float dist = Vector3.Distance(HammerRigid.gameObject.transform.up, -Vector3.up); //print(dist); if (!needHammerCorrect && vel.y < 0 && !prevGrounded) { needHammerCorrect = true; } if (shouldClimb) { vel.y = jumpSpeed / 1f; vel.x = speedX; shouldClimb = false; print("climb!"); } if (grounded && isTakingOff) //give hero jump speed { if (HammerLeft && hammerExactLeft()) { vel.y = jumpSpeed; } if (!HammerLeft && hammerExactRight()) { vel.y = jumpSpeed; } } if (grounded && !isTakingOff && needHammerCorrect) { if (HammerRigid.gameObject.transform.localPosition.y >= 0) // hammer is above ground { vel = Vector3.zero; //no bounce switchHammer(); needHammerCorrect = false; } //put down hammer if (HammerLeft) { HammerRigid.AddForce(-Vector3.right * jumpForce, ForceMode.Impulse); HammerLeft = false; } else { HammerRigid.AddForce(Vector3.right * jumpForce, ForceMode.Impulse); HammerLeft = true; } } //else if (grounded && !isTakingOff && HammerRigid.gameObject.transform.localPosition.y > 0.1) if (Mathf.Abs(vel.y) > 0.5f && hammerExactUp() && RotateSeq.getRightJQ() == 0) //0.5f means !grounded { HammerRigid.gameObject.transform.up = Vector3.right; HammerRigid.angularVelocity = Vector3.zero; HammerRigid.velocity = Vector3.zero; isTakingOff = false; } else if (vel.y <= -0.5f) { isTakingOff = false; } bodyRigid.velocity = vel; //========== hammer no bounce ============== if (!isTakingOff && HammerLeft && hammerExactRight()) { HammerRigid.angularVelocity = Vector3.zero; HammerRigid.velocity = Vector3.zero; HammerLeft = false; RodRigid.gameObject.transform.eulerAngles = new Vector3(0, 0, -90); } if (!isTakingOff && !HammerLeft && hammerExactLeft()) { HammerRigid.angularVelocity = Vector3.zero; HammerRigid.velocity = Vector3.zero; HammerLeft = true; RodRigid.gameObject.transform.eulerAngles = new Vector3(0, 0, 90); } //========= switch hammer/propeller ========= if (!grounded) { if (Input.GetAxis("Trigger") > 0.2 && HammerRigid.gameObject.transform.localPosition.y > 0) { switchHammer(); } else if (Input.GetAxis("Trigger") <= 0) { switchPropeller(); } } else //grounded { if (Input.GetAxis("Trigger") > 0.2 && HammerRigid.gameObject.transform.localPosition.y < -0.1) { switchPropeller(); HammerRigid.gameObject.layer = LayerMask.NameToLayer("HammerJump"); needHammerCorrect = true; } else if (prevGrounded && Input.GetAxis("Trigger") <= 0 && HammerRigid.gameObject.transform.localPosition.y > 0) { switchHammer(); } } }