diff --git a/enginecustom/applicationclass.cpp b/enginecustom/applicationclass.cpp index c1caa1c..ce87f5f 100644 --- a/enginecustom/applicationclass.cpp +++ b/enginecustom/applicationclass.cpp @@ -740,7 +740,7 @@ bool ApplicationClass::Frame(InputClass* Input) object->SetPosition(XMVectorSetY(currentPosition, 20.0f)); // Define the new position of the object } m_Physics->ApplyGravity(object, frameTime); - m_Physics->ApplyDrag(object, 0.1f, frameTime); + m_Physics->ApplyDrag(object, 1.0f, frameTime); // Update object position based on its velocity XMVECTOR position = object->GetPosition(); XMVECTOR velocity = object->GetVelocity(); diff --git a/enginecustom/physics.cpp b/enginecustom/physics.cpp index f2a371e..cc7561d 100644 --- a/enginecustom/physics.cpp +++ b/enginecustom/physics.cpp @@ -1,9 +1,8 @@ #include "physics.h" -Physics::Physics() +Physics::Physics() : m_gravity(XMVectorSet(0.0f, -9.81f, 0.0f, 0.0f)) // Initialize the gravity vector { - m_gravity = -9.81f; // Initilize the gravity value } Physics::Physics(const Physics& other) @@ -16,13 +15,13 @@ Physics::~Physics() } // Get the gravity value -float Physics::GetGravity() +XMVECTOR Physics::GetGravity() { return m_gravity; } // Define the gravity value -void Physics::SetGravity(float gravity) +void Physics::SetGravity(XMVECTOR gravity) { m_gravity = gravity; } @@ -38,8 +37,8 @@ void Physics::ApplyGravity(Object* object, float frameTime) // Get the object velocity XMVECTOR velocity = object->GetVelocity(); - // Update the Y component of the velocity - velocity = XMVectorSetY(velocity, XMVectorGetY(velocity) + m_gravity * frameTime); + // Update the velocity with gravity + velocity += m_gravity * frameTime; // Set the new velocity object->SetVelocity(velocity); diff --git a/enginecustom/physics.h b/enginecustom/physics.h index 0084708..1a2893d 100644 --- a/enginecustom/physics.h +++ b/enginecustom/physics.h @@ -10,14 +10,13 @@ public: explicit Physics(const Physics&); // Use explicit to avoid implicit conversion ~Physics(); - float GetGravity(); // Get the gravity value - void SetGravity(float gravity); // Define the gravity value + XMVECTOR GetGravity(); // Get the gravity value + void SetGravity(XMVECTOR gravity); // Define the gravity value void ApplyGravity(Object*, float); // Apply gravity to an object void ApplyDrag(Object*, float, float); - private: - float m_gravity; + XMVECTOR m_gravity; }; #endif \ No newline at end of file