2
0

WasdPlayerMovementComponent.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0 OR MIT
  5. *
  6. */
  7. #pragma once
  8. #include <Source/AutoGen/WasdPlayerMovementComponent.AutoComponent.h>
  9. #include <StartingPointInput/InputEventNotificationBus.h>
  10. namespace MultiplayerSample
  11. {
  12. // Input Event Ids for Player Controls
  13. const StartingPointInput::InputEventNotificationId MoveFwdEventId("move_fwd");
  14. const StartingPointInput::InputEventNotificationId MoveBackEventId("move_back");
  15. const StartingPointInput::InputEventNotificationId MoveLeftEventId("move_left");
  16. const StartingPointInput::InputEventNotificationId MoveRightEventId("move_right");
  17. const StartingPointInput::InputEventNotificationId SprintEventId("sprint");
  18. const StartingPointInput::InputEventNotificationId JumpEventId("jump");
  19. const StartingPointInput::InputEventNotificationId CrouchEventId("crouch");
  20. const StartingPointInput::InputEventNotificationId LookLeftRightEventId("lookLeftRight");
  21. const StartingPointInput::InputEventNotificationId LookUpDownEventId("lookUpDown");
  22. class WasdPlayerMovementComponentController
  23. : public WasdPlayerMovementComponentControllerBase
  24. , private StartingPointInput::InputEventNotificationBus::MultiHandler
  25. {
  26. public:
  27. WasdPlayerMovementComponentController(WasdPlayerMovementComponent& parent);
  28. void OnActivate(Multiplayer::EntityIsMigrating entityIsMigrating);
  29. void OnDeactivate(Multiplayer::EntityIsMigrating entityIsMigrating);
  30. void CreateInput(Multiplayer::NetworkInput& input, float deltaTime) override;
  31. void ProcessInput(Multiplayer::NetworkInput& input, float deltaTime) override;
  32. private:
  33. void UpdateVelocity(const WasdPlayerMovementComponentNetworkInput& wasdInput);
  34. float NormalizeHeading(float heading) const;
  35. //! AZ::InputEventNotificationBus interface
  36. //! @{
  37. void OnPressed(float value) override;
  38. void OnReleased(float value) override;
  39. void OnHeld(float value) override;
  40. //! @}
  41. float m_forwardWeight = 0.0f;
  42. float m_leftWeight = 0.0f;
  43. float m_backwardWeight = 0.0f;
  44. float m_rightWeight = 0.0f;
  45. float m_viewYaw = 0.0f;
  46. float m_viewPitch = 0.0f;
  47. bool m_forwardDown = false;
  48. bool m_leftDown = false;
  49. bool m_backwardDown = false;
  50. bool m_rightDown = false;
  51. bool m_sprinting = false;
  52. bool m_jumping = false;
  53. bool m_crouching = false;
  54. };
  55. }