void Land() { Vector3 travelDirection = rb.velocity; travelDirection.y = 0; Vector3 lookDirection = transform.forward; lookDirection.y = 0; if (Vector3.Angle(travelDirection, lookDirection) < 30) { RidingState = RidingStates.REGULAR; } else if (Vector3.Angle(travelDirection, -lookDirection) < 30) { RidingState = RidingStates.REGULAR_BLIND; } else { RidingState = RidingStates.CRASHED; Debug.Log("CRASH"); rb.constraints = RigidbodyConstraints.None; } }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Q)) { transform.position = new Vector3(0, 0.6f, -5); rb.velocity = Vector3.zero; RidingState = RidingStates.REGULAR; PlayerState = PlayerStates.RIDING; rb.constraints = RigidbodyConstraints.FreezeRotation; } inputVector = Vector3.zero; inputVector.x = Input.GetAxis("Horizontal"); inputVector.z = Input.GetAxis("Vertical"); if (moveVector == Vector3.zero) { moveVector = rb.velocity; } IsGrounded(); if (RidingState == RidingStates.CRASHED) { return; } Move(); Steer(); Dampen(); if (PlayerState == PlayerStates.RIDING) { if (RidingState == RidingStates.REGULAR) { transform.LookAt(transform.position + new Vector3(rb.velocity.x, 0, rb.velocity.z)); } else if (RidingState == RidingStates.REGULAR_BLIND) { transform.LookAt(transform.position - new Vector3(rb.velocity.x, 0, rb.velocity.z)); } } if (moveVector != Vector3.zero) { rb.velocity = moveVector; } Debug.DrawRay(transform.position, moveVector, Color.black, 20); moveVector = Vector3.zero; }