NetworkTeleportComponent.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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
  3. * this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <Source/AutoGen/NetworkTeleportComponent.AutoComponent.h>
  10. #include <AzFramework/Physics/Common/PhysicsSimulatedBody.h>
  11. #include <AzFramework/Physics/Common/PhysicsSimulatedBodyEvents.h>
  12. #include <AzFramework/Physics/RigidBodyBus.h>
  13. namespace MultiplayerSample
  14. {
  15. /**
  16. * @brief Transports entities that collide with it to a fixed location.
  17. *
  18. */
  19. class NetworkTeleportComponent
  20. : public NetworkTeleportComponentBase
  21. {
  22. public:
  23. AZ_COMPONENT(NetworkTeleportComponent, "{917a6318-e047-4ec5-b6ed-bc95f74bd287}",
  24. NetworkTeleportComponentBase);
  25. static void Reflect(AZ::ReflectContext* reflection);
  26. void OnInit() override {};
  27. void OnActivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating) override;
  28. void OnDeactivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating) override;
  29. #if AZ_TRAIT_CLIENT
  30. void HandleNotifyTeleport(AzNetworking::IConnection* invokingConnection) override;
  31. #endif
  32. private:
  33. GameEffect m_effect;
  34. };
  35. class NetworkTeleportComponentController
  36. : public NetworkTeleportComponentControllerBase
  37. , private Physics::RigidBodyNotificationBus::Handler
  38. {
  39. public:
  40. NetworkTeleportComponentController(NetworkTeleportComponent& parent);
  41. void OnActivate(Multiplayer::EntityIsMigrating entityIsMigrating) override;
  42. void OnDeactivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating) override;
  43. private:
  44. void OnPhysicsEnabled(const AZ::EntityId& entityId) override;
  45. void OnPhysicsDisabled(const AZ::EntityId& entityId) override;
  46. AzPhysics::SimulatedBodyEvents::OnTriggerEnter::Handler m_enterTrigger;
  47. void OnTriggerEnter(
  48. AzPhysics::SimulatedBodyHandle bodyHandle, const AzPhysics::TriggerEvent& triggerEvent);
  49. AZ::Entity* GetCollidingEntity(AzPhysics::SimulatedBody* collidingBody) const;
  50. AZ::Vector3 GetDestinationVector() const;
  51. void TeleportPlayer(const AZ::Vector3& vector, AZ::Entity* entity);
  52. };
  53. } // namespace MultiplayerSample