Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #ifndef SIMPLEFPSCONTOLLER_H
- #define SIMPLEFPSCONTOLLER_H
- #include <AzCore/Component/Component.h>
- #include <AzCore/Component/EntityBus.h>
- #include <AzCore/Component/TickBus.h>
- #include <AzFramework/Input/Events/InputChannelEventListener.h>
- #include "..\..\..\Gems\Camera\Code\Source\CameraComponent.h"
- // EBUS
- #include <AzFramework/Entity/GameEntityContextBus.h>
- #include <AzFramework\Components\CameraBus.h>
- namespace GameProject
- {
- class SimpleFPSContoller:
- public AZ::Component,
- public AZ::EntityBus::MultiHandler,
- public AZ::TickBus::Handler,
- public AzFramework::InputChannelEventListener,
- public AzFramework::GameEntityContextEventBus::Handler
- {
- enum InputMask : AZ::u8
- {
- eINPUT_NONE = 0,
- eINPUT_FORWARD = 1,
- eINPUT_BACK = 1 << 1,
- eINPUT_RIGHT = 1 << 2,
- eINPUT_LEFT = 1 << 3,
- eINPUT_UP = 1 << 4,
- eINPUT_DOWN = 1 << 5,
- eINPUT_MOUSE_X = 1 << 6,
- eINPUT_MOUSE_Y = 1 << 7,
- };
- public:
- AZ_COMPONENT(SimpleFPSContoller, "{9F834A4E-3041-4626-A296-B1662AE82AC6}", AZ::Component);
- SimpleFPSContoller();
- virtual ~SimpleFPSContoller();
- static void Reflect(AZ::ReflectContext* context);
- void Init() override;
- void Activate() override;
- void Deactivate() override;
- // AzFramework::InputChannelEventListener
- bool OnInputChannelEventFiltered(const AzFramework::InputChannel& inputChannel) override;
- // AZ::TickBus
- void OnTick(float deltaTime, AZ::ScriptTimePoint time);
- //GameEntityContextEventBus
- void OnGameEntitiesStarted() override;
- bool IsPointInView(AZ::Vector3 pos);
- private:
- void OnMouseEvent(const AzFramework::InputChannel& inputChannel);
- void OnKeyboardEvent(const AzFramework::InputChannel& inputChannel);
- void DrawDebug();
- void RayCastForward();
- void RayCastForward2();
- void GatherAroundHit();
- AZ::u8 m_MovementMasks = InputMask::eINPUT_NONE;
- float m_yawChange = 0.0f;
- float m_pitchChange = 0.0f;
- float m_yaw = 0.0f;
- float m_pitch = 0.0f;
- float m_boost = 1.0f;
- AZ::Vector3 m_worldStartPosition;
- AZ::Quaternion m_worldStartRotation;
- float m_yawSaved = 0.0f;
- float m_pitchSaved = 0.0f;
- AZ::Entity* childEntity = nullptr;
- //ratcast debug
- AZ::Vector3 m_rayStartPosition = AZ::Vector3::CreateZero();
- AZ::Vector3 m_rayEndPosition = AZ::Vector3::CreateZero();
- AZ::Vector3 m_hitPosition = AZ::Vector3::CreateZero();
- AZ::Vector3 m_hitNormal = AZ::Vector3::CreateZero();
- AZ::EntityId m_hitEntityId;
- AZ::Entity* m_hitEntity = nullptr;
- AZStd::string m_hitName;
- float m_gatherRadius = 2.0f;
- AZ::Vector3 m_gatherPosition = AZ::Vector3::CreateZero();
- AZStd::string m_label;
- //Editor exposed properties
- float m_yawRotationSpeed = 6;
- float m_pitchRotationSpeed = 4;
- };
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement