private void Move() { Vector3 lookingDirection = transform.rotation * Vector3.forward; Vector3 inputVelocity; inputVelocity.x = movementSpeed * movementInput.x; inputVelocity.y = 0f; inputVelocity.z = movementSpeed * movementInput.y; float angleRadians = inputVelocity.AngleDegreesBetween(lookingDirection) * Mathf.Deg2Rad; Vector3 newVelocity = inputVelocity * (Mathf.Cos(angleRadians * 0.5f) * lookingDirectionFactor + (1f - lookingDirectionFactor)); newVelocity.y = rb.velocity.y; rb.velocity = Vector3.Lerp(rb.velocity, newVelocity, movementSpeed * 2 * Time.deltaTime); Direction currentDirection = GetDirection(); if (currentDirection != lastDirection) { OnMovementDirectionChanged?.Invoke(currentDirection); lastDirection = currentDirection; } }
// Update is called once per frame void Update() { if (Input.GetKeyUp(KeyCode.LeftArrow)) { ON_DIRECTION.Invoke(new Vector2(-1, 0)); } else if (Input.GetKeyUp(KeyCode.RightArrow)) { ON_DIRECTION.Invoke(new Vector2(1, 0)); } else if (Input.GetKeyUp(KeyCode.UpArrow)) { ON_DIRECTION.Invoke(new Vector2(0, -1)); } else if (Input.GetKeyUp(KeyCode.DownArrow)) { ON_DIRECTION.Invoke(new Vector2(0, 1)); } }
public void SecondJump(JoystickValues joystickValues) { _hasDoneFirstJump = false; _straightUpSecondJump = false; var direction = Direction.Default; Vector3 forceDirection; if (joystickValues.X < -0.5f) { forceDirection = Vector3.left; direction = Direction.Left; } else if (joystickValues.X > 0.5f) { forceDirection = Vector3.right; direction = Direction.Right; } else if (joystickValues.Y > 0.5f || Input.GetButton(Constants.Input.Accelerate)) { forceDirection = Vector3.forward; direction = Direction.Forward; } else if (joystickValues.Y < -0.5f || Input.GetButton(Constants.Input.Decelerate)) { forceDirection = Vector3.back; direction = Direction.Backward; } else { // forceDirection = Vector3.forward; // direction = Direction.Forward; forceDirection = Vector3.up; _straightUpSecondJump = true; } var forceUp = Vector3.up * _jumpSettings.SecondJumpUpForce; var forceDirectional = forceDirection * _jumpSettings.SecondJumpLateralForces; if (_straightUpSecondJump) { _rb.AddRelativeForce(forceUp, ForceMode.Impulse); } else { _rb.AddRelativeForce(forceUp + forceDirectional, ForceMode.Impulse); StartCoroutine(CancelJumpVelocity(forceDirectional)); } OnSecondJump.Invoke(direction); }
void GetDirectionInput() { var direction = new Vector2(); if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A)) { direction.x = -1; } else if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D)) { direction.x = 1; } DirectionInput?.Invoke(direction); }
static void KeyReader() { while (play) { if (Console.KeyAvailable) { ConsoleKey k = Console.ReadKey(true).Key; switch (k) { case ConsoleKey.Spacebar: { delay -= 25; if (delay < 25) { delay = 25; } break; } case ConsoleKey.Enter: { delay += 25; if (delay > 600) { delay = 600; } break; } case ConsoleKey.UpArrow: { DirectionEvent?.Invoke(direction.up); break; } case ConsoleKey.LeftArrow: { DirectionEvent?.Invoke(direction.left); break; } case ConsoleKey.DownArrow: { DirectionEvent?.Invoke(direction.down); break; } case ConsoleKey.RightArrow: { DirectionEvent?.Invoke(direction.right); break; } case ConsoleKey.Escape: { break; } } } } }
private void MoveOnPerformed(InputAction.CallbackContext ctx) => directionEvent.Invoke(ctx.ReadValue <Vector2>());