Recoil while firing, clamp inputs, merge Helicopter
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
|
||||
void Systems::HelicopterSteeringSystem::RegisterComponents(ComponentFactory* cf)
|
||||
{
|
||||
cf->Register("HelicopterSteering", []() { return new Components::HelicopterSteering(); });
|
||||
cf->Register<Components::HelicopterSteering>([]() { return new Components::HelicopterSteering(); });
|
||||
}
|
||||
|
||||
void Systems::HelicopterSteeringSystem::Initialize()
|
||||
@@ -19,11 +19,11 @@ void Systems::HelicopterSteeringSystem::Update(double dt)
|
||||
|
||||
void Systems::HelicopterSteeringSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||
{
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||
if (!transform)
|
||||
return;
|
||||
|
||||
auto helicopterComponent = m_World->GetComponent<Components::HelicopterSteering>(entity, "HelicopterSteering");
|
||||
auto helicopterComponent = m_World->GetComponent<Components::HelicopterSteering>(entity);
|
||||
if (helicopterComponent)
|
||||
{
|
||||
glm::vec3 controllerRotationEuler = m_InputController->Rotation * (float)dt;
|
||||
|
||||
@@ -35,7 +35,8 @@ void Systems::PhysicsSystem::Initialize()
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ETankSteer, &Systems::PhysicsSystem::OnTankSteer);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ESetVelocity, &Systems::PhysicsSystem::OnSetVelocity);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EApplyForce, &Systems::PhysicsSystem::OnApplyForce);
|
||||
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EApplyPointImpulse, &Systems::PhysicsSystem::OnApplyPointImpulse);
|
||||
|
||||
hkMemorySystem::FrameInfo finfo(6000 * 1024); // Allocate 6MB of Physics solver buffer
|
||||
hkMemoryRouter* memoryRouter = hkMemoryInitUtil::initDefault(hkMallocAllocator::m_defaultMallocAllocator, finfo);
|
||||
hkBaseSystem::init(memoryRouter, HavokErrorReport);
|
||||
@@ -605,3 +606,12 @@ bool Systems::PhysicsSystem::OnApplyForce(const Events::ApplyForce &event)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Systems::PhysicsSystem::OnApplyPointImpulse( const Events::ApplyPointImpulse &event )
|
||||
{
|
||||
m_PhysicsWorld->markForWrite();
|
||||
m_RigidBodies[event.Entity]->applyPointImpulse(ConvertPosition(event.Impulse), ConvertPosition(event.Position));
|
||||
m_PhysicsWorld->unmarkForWrite();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "Events/TankSteer.h"
|
||||
#include "Events/SetVelocity.h"
|
||||
#include "Events/ApplyForce.h"
|
||||
#include "Events/ApplyPointImpulse.h"
|
||||
#include "OBJ.h"
|
||||
|
||||
// Math and base include
|
||||
@@ -108,6 +109,8 @@ private:
|
||||
bool OnSetVelocity(const Events::SetVelocity &event);
|
||||
EventRelay<Events::ApplyForce> m_EApplyForce;
|
||||
bool OnApplyForce(const Events::ApplyForce &event);
|
||||
EventRelay<Events::ApplyPointImpulse> m_EApplyPointImpulse;
|
||||
bool OnApplyPointImpulse(const Events::ApplyPointImpulse &event);
|
||||
|
||||
void SetUpPhysicsState(EntityID entity, EntityID parent);
|
||||
void TearDownPhysicsState(EntityID entity, EntityID parent);
|
||||
|
||||
@@ -62,6 +62,17 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
|
||||
e.Velocity = absoluteTransform.Orientation * (glm::vec3(0.f, 0.f, -1.f) * barrelSteeringComponent->ShotSpeed);
|
||||
EventBroker->Publish(e);
|
||||
m_TimeSinceLastShot[entity] = 0;
|
||||
|
||||
|
||||
auto clonePhysicsComponent = m_World->GetComponent<Components::Physics>(clone);
|
||||
//1,670m/s
|
||||
//25kg
|
||||
EntityID baseParent = m_World->GetEntityBaseParent(entity);
|
||||
Events::ApplyPointImpulse ePointImpulse ;
|
||||
ePointImpulse.Entity = baseParent;
|
||||
ePointImpulse.Position = absoluteTransform.Position;
|
||||
ePointImpulse.Impulse = glm::normalize(absoluteTransform.Orientation * glm::vec3(0, 0, 1)) * clonePhysicsComponent->Mass * 1670.f;
|
||||
EventBroker->Publish(ePointImpulse);
|
||||
}
|
||||
|
||||
m_TimeSinceLastShot[entity] += dt;
|
||||
@@ -83,7 +94,16 @@ void Systems::TankSteeringSystem::TowerSteeringInputController::Update( double d
|
||||
|
||||
bool Systems::TankSteeringSystem::TankSteeringInputController::OnCommand(const Events::InputCommand &event)
|
||||
{
|
||||
float val = event.Value;
|
||||
float val;
|
||||
if(abs(event.Value) < 0.3f)
|
||||
{
|
||||
val = 0.f;
|
||||
}
|
||||
else
|
||||
{
|
||||
val = event.Value;
|
||||
}
|
||||
|
||||
if (event.Command == "horizontal")
|
||||
{
|
||||
m_Horizontal = val;
|
||||
|
||||
@@ -3,10 +3,13 @@
|
||||
#include "System.h"
|
||||
#include "Events/TankSteer.h"
|
||||
#include "Events/SetVelocity.h"
|
||||
#include "Events/ApplyForce.h"
|
||||
#include "Events/ApplyPointImpulse.h"
|
||||
#include "Components/Transform.h"
|
||||
#include "Components/TankSteering.h"
|
||||
#include "Components/TowerSteering.h"
|
||||
#include "Components/BarrelSteering.h"
|
||||
#include "Components/Physics.h"
|
||||
#include "Components/Vehicle.h"
|
||||
#include "Systems/TransformSystem.h"
|
||||
#include "InputController.h"
|
||||
|
||||
Reference in New Issue
Block a user