private void FixedUpdate() { if (inRange) { if (InVehicle) { if (Input.GetButtonDown("Item")) { Debug.Log("Get Out Vehicle"); transform.parent = null; InVehicle = false; manager.MovementEnable(true); } Vehicle.transform.Rotate(0, Input.GetAxis("Horizontal") * Time.deltaTime * rotationSpeed, 0); Vehicle.transform.Translate(0, 0, Input.GetAxis("Vertical") * Time.deltaTime * movementSpeed); } else { if (Input.GetButtonDown("Item")) { Debug.Log("Get Into Vehicle"); InVehicle = true; transform.parent = Vehicle.transform; transform.rotation = AttachPoint.transform.rotation; transform.position = AttachPoint.transform.position; manager.MovementEnable(false); } } } }
private IEnumerator JumpFunc() { while (canJump) { if (Input.GetKeyDown(KeyCode.Space)) { if (onGround || MAX_JUMPS > currentJump) { gravity = 0; rigidBody.AddForce(Vector3.up * jumpSpeed, ForceMode.Impulse); onGround = false; currentJump++; } else if (wallJump.value) { if (collided) { gravity = 0; Debug.Log("Wall Jump"); manager.MovementEnable(false); jumpDirection = GetDirection(transform.rotation.eulerAngles.y); newRot = transform.rotation.eulerAngles; newRot.y = (newRot.y + 180) % 360; transform.rotation = Quaternion.Euler(newRot); jumpDirection *= -1f; jumpDirection.y = 1.5f; jumpDirection *= jumpSpeed; rigidBody.AddForce(jumpDirection, ForceMode.Impulse); yield return(new WaitForSeconds(.25f)); manager.MovementEnable(true); } } } if (gravity < 1) { gravity += Time.deltaTime; } if (gravity > 1) { gravity = 1; } velocity = rigidBody.velocity; velocity.y -= gravity; rigidBody.velocity = velocity; yield return(new WaitForFixedUpdate()); } }
private IEnumerator OnCollisionEnter(Collision other) { if (other.gameObject.CompareTag("Pushable")) { pushObj = other.gameObject; if (!isPushing) { obj = other.gameObject.GetComponent <Pushable_Object_holder>(); if (obj.obj.isPushable) { canPush = true; CheckDirection(); yield return(new WaitForSeconds(.25f)); if (canPush) { manager.MovementEnable(false); manager.WeaponEnable(false); StartCoroutine(Pushing(pushObj)); } } } } }