Plasma Engine  2.0
Loading...
Searching...
No Matches
ProjectileComponent.h
1#pragma once
2
3#include <Core/Physics/SurfaceResource.h>
4#include <Core/World/Component.h>
5#include <Core/World/World.h>
6#include <GameComponentsPlugin/GameComponentsDLL.h>
7
9
11
13struct PL_GAMECOMPONENTS_DLL plProjectileReaction
14{
15 using StorageType = plInt8;
16
17 enum Enum : StorageType
18 {
24
25 Default = Absorb
26 };
27};
28
29PL_DECLARE_REFLECTABLE_TYPE(PL_GAMECOMPONENTS_DLL, plProjectileReaction);
30
32struct PL_GAMECOMPONENTS_DLL plProjectileSurfaceInteraction
33{
34 void SetSurface(const char* szSurface);
35 const char* GetSurface() const;
36
39
42
45
47 float m_fImpulse = 0.0f;
48
50 float m_fDamage = 0.0f;
51};
52
53PL_DECLARE_REFLECTABLE_TYPE(PL_GAMECOMPONENTS_DLL, plProjectileSurfaceInteraction);
54
59class PL_GAMECOMPONENTS_DLL plProjectileComponent : public plComponent
60{
62
64 // plComponent
65
66public:
67 virtual void SerializeComponent(plWorldWriter& inout_stream) const override;
68 virtual void DeserializeComponent(plWorldReader& inout_stream) override;
69
70protected:
71 virtual void OnSimulationStarted() override;
72
73
75 // plProjectileComponent
76
77public:
80
82 float m_fMetersPerSecond; // [ property ]
83
85 float m_fGravityMultiplier; // [ property ]
86
87 // If true the death prefab will be spawned when the velocity gones under the threshold to be considered static
88 bool m_bSpawnPrefabOnStatic; // [ property ]
89
91 plUInt8 m_uiCollisionLayer; // [ property ]
92
95
97 plTime m_MaxLifetime; // [ property ]
98
101
104
106 void SetDeathPrefab(const char* szPrefab); // [ property ]
107 const char* GetDeathPrefab() const; // [ property ]
108
109 void SetFallbackSurfaceFile(const char* szFile); // [ property ]
110 const char* GetFallbackSurfaceFile() const; // [ property ]
111
112private:
113 void Update();
114 void OnTriggered(plMsgComponentInternalTrigger& msg); // [ msg handler ]
115
116 void SpawnDeathPrefab();
117
118 plPrefabResourceHandle m_hDeathPrefab;
119
121 plInt32 FindSurfaceInteraction(const plSurfaceResourceHandle& hSurface) const;
122
123 void TriggerSurfaceInteraction(const plSurfaceResourceHandle& hSurface, plGameObjectHandle hObject, const plVec3& vPos, const plVec3& vNormal, const plVec3& vDirection, const char* szInteraction);
124
125 plVec3 m_vVelocity;
126};
Base class of all component types.
Definition Component.h:25
Simple component manager implementation that calls an update method on all components every frame.
Definition ComponentManager.h:142
A hybrid array uses in-place storage to handle the first few elements without any allocation....
Definition HybridArray.h:12
Shoots a game object in a straight line and uses physics raycasts to detect hits.
Definition ProjectileComponent.h:60
float m_fGravityMultiplier
If 0, the projectile is not affected by gravity.
Definition ProjectileComponent.h:85
plTime m_MaxLifetime
After this time the projectile is removed, if it didn't hit anything yet.
Definition ProjectileComponent.h:97
float m_fMetersPerSecond
The speed at which the projectile flies.
Definition ProjectileComponent.h:82
plSurfaceResourceHandle m_hFallbackSurface
If the projectile hits something that has no valid surface, this surface is used instead.
Definition ProjectileComponent.h:100
plUInt8 m_uiCollisionLayer
Defines which other physics objects the projectile will collide with.
Definition ProjectileComponent.h:91
plBitflags< plPhysicsShapeType > m_ShapeTypesToHit
A broad filter to ignore certain types of colliders.
Definition ProjectileComponent.h:94
plHybridArray< plProjectileSurfaceInteraction, 12 > m_SurfaceInteractions
Specifies how the projectile interacts with different surface types.
Definition ProjectileComponent.h:103
Reads a world description from a stream. Allows to instantiate that world multiple times in different...
Definition WorldReader.h:47
Stores an entire plWorld in a stream.
Definition WorldWriter.h:13
The plBitflags class allows you to work with type-safe bitflags.
Definition Bitflags.h:82
A handle to a game object.
Definition Declarations.h:76
For internal use by components to trigger some known behavior. Usually components will post this mess...
Definition TriggerMessage.h:26
Defines what a projectile will do when it hits a surface.
Definition ProjectileComponent.h:14
Enum
Definition ProjectileComponent.h:18
@ PassThrough
Continues flying through the geometry (but may spawn prefabs at the intersection points)
Definition ProjectileComponent.h:23
@ Bounce
Bounces away along the reflected direction. Loses momentum.
Definition ProjectileComponent.h:21
@ Reflect
Bounces away along the reflected direction. Maintains momentum.
Definition ProjectileComponent.h:20
@ Absorb
The projectile simply stops and is deleted.
Definition ProjectileComponent.h:19
@ Attach
Stops at the hit point, does not continue further and attaches itself as a child to the hit object.
Definition ProjectileComponent.h:22
Holds the information about how a projectile interacts with a specific surface type.
Definition ProjectileComponent.h:33
plProjectileReaction::Enum m_Reaction
How the projectile itself will react when hitting the surface type.
Definition ProjectileComponent.h:41
plString m_sInteraction
Which interaction should be triggered. See plSurfaceResource.
Definition ProjectileComponent.h:44
plSurfaceResourceHandle m_hSurface
The surface type (and derived ones) for which this interaction is used.
Definition ProjectileComponent.h:38
The time class encapsulates a double value storing the time in seconds.
Definition Time.h:12