public void checkJumping() { if (ControllerInput.A_ButtonDown(id) || (allowKeyboardInput && Input.GetKeyDown(KeyCode.Space))) { if (charController.isGrounded) { Debug.Log("jump"); if (mode == PlayerMode.Small) { verticalSpeed = verticalStab; } else if (mode == PlayerMode.Big) { verticalSpeed = verticalStab * 0.5f; } } } }
void Update() { //Game mode GameMode(); float moveHorizontal; float moveVertical; if (allowKeyboardInput) { moveVertical = Input.GetAxis("Vertical"); moveHorizontal = Input.GetAxis("Horizontal"); } else { moveVertical = ControllerInput.LeftAnalog_Y_Axis(id, 0.2f); moveHorizontal = ControllerInput.LeftAnalog_X_Axis(id, 0.2f); } Vector3 movementInput = new Vector3(moveHorizontal, 0, moveVertical); movementInput = movementInput.normalized; //Debug.Log (seeSaw.transform.localRotation.eulerAngles.x); moveDir = movementInput; //uaternion.AngleAxis(-seeSaw.transform.rotation.eulerAngles.x, Vector3.forward) * Debug.DrawLine(new Vector3(0,2,0), new Vector3(moveDir.x, 2 + moveDir.y, moveDir.z), Color.green); Debug.DrawLine(transform.position, (((transform.position + moveDir.normalized) - transform.position) * 3) + transform.position, Color.green); if (ControllerInput.A_ButtonDown(id) || (allowKeyboardInput && Input.GetKeyDown(KeyCode.LeftShift))) { //currentSpeed *= 1.4f; currentSpeed = Mathf.Lerp(currentSpeed * 1.2f, 1, acceleration * Time.deltaTime); } if (Input.GetKeyUp(KeyCode.LeftShift)) { //currentSpeed /= 1.4f; currentSpeed = Mathf.Lerp(0, currentSpeed / 1.2f, acceleration * Time.deltaTime); } if (movementInput.magnitude > 0) { //RotateToMovement(playerBody, movementInput.x, movementInput.z, 12); currentSpeed = Mathf.Lerp(currentSpeed, 0.7f, acceleration * Time.deltaTime); } else { currentSpeed = Mathf.Lerp(0, currentSpeed, acceleration * Time.deltaTime); } movementMag = movement.magnitude; // moveDir = Quaternion.AngleAxis(seeSaw.transform.rotation.z, Vector3.forward) * moveDir; //Debug.DrawLine(transform.position, (transform.position + new Vector3(moveDir.x, 0, moveDir.z)) * 2, Color.green); moveDir *= currentSpeed * Time.deltaTime; movement += moveDir; //Quaternion.FromToRotation(Vector3.forward, -target) * movement += (linearDampening * -new Vector3(movement.x, 0, movement.z)); ApplyGravity (); isGrounded = charController.isGrounded; checkJumping(); //charController.Move(movement); //Vector3.ClampMagnitude(movement, maxSpeed); if (id ==1) // Debug.Log (verticalSpeed); movement = new Vector3(movement.x, verticalSpeed, movement.z); if(movement.x > 0 && !FacingRight) { Flip(); }else if (movement.x < 0 && FacingRight) { Flip(); } //transform.position = Vector3.Lerp(transform.position, movement + transform.position, movementSmoothing); Debug.DrawLine(transform.position, (((transform.position + movement.normalized) - transform.position) * movement.magnitude * 1.4f) + transform.position, Color.red); charController.Move(movement); transform.position = new Vector3(transform.position.x, transform.position.y, 0); grabObject(); throwObject(); }