fix du probleme de spawn d'objets

fix:

+ les objets ne s'envolent plus vers le haut quand un nouvel objet est spawn
This commit is contained in:
StratiX0
2024-04-22 16:14:05 +02:00
parent d51619f437
commit 4a77df6102
4 changed files with 11 additions and 30 deletions

View File

@@ -28,7 +28,7 @@ void Physics::SetGravity(XMVECTOR gravity)
}
// Apply gravity to an object
void Physics::ApplyGravity(Object* object, float frameTime)
void Physics::ApplyGravity(Object* object, float dragValue, float frameTime)
{
if (object == nullptr) // Verify if the object is not null
{
@@ -41,30 +41,13 @@ void Physics::ApplyGravity(Object* object, float frameTime)
// Add the gravity acceleration to the object's current acceleration
object->SetAcceleration(object->GetAcceleration() + gravityAcceleration);
// Get the object velocity
XMVECTOR velocity = object->GetVelocity();
// Update the velocity with the object's acceleration
velocity += object->GetAcceleration() * frameTime;
// Set the new velocity
object->SetVelocity(velocity);
}
void Physics::ApplyDrag(Object* object, float dragValue, float frameTime)
{
if (object == nullptr) // Verify if the object is not null
{
return;
}
// Calculate the acceleration caused by drag
XMVECTOR dragAcceleration = -object->GetVelocity() * dragValue / object->GetMass();
// Add the drag acceleration to the object's current acceleration
object->SetAcceleration(object->GetAcceleration() + dragAcceleration);
// Get the velocity of the object
// Get the object velocity
XMVECTOR velocity = object->GetVelocity();
// Update the velocity with the object's acceleration