How to stop projectile from sinking

So I implemented a projectile for my game but when thrown, the projectile will collide and stop but will slowly start sink down bit by bit.

The code below is when you hit the boundary what will happen. So once you hit the boundary it will stop.

if (grenadePosition.y >= 500 || grenadePosition.x >= 1000 || grenadePosition.x < 0) <-this is my screen boundaries 
{
    
    printf("Grenade Position %.2f - %.2fn", grenadePosition.x, grenadePosition.y);
    grenadePosition.x = grenadePosition.x;
    grenadePosition.y = grenadePosition.y;
    /*grenadeVelocity = (grenadeDirection * grenadeSpeed / 60.0f);*/
    grenadeVelocity.x = 0;
    grenadeVelocity.y = 0;
}

This is the code for the projectile when it is shot.

isGrenadeMove = true;
    grenadeSpeed = 200;
    if (degree <= 90)
    {
        degree = 90 - degree;
        grenadeDirection.x = sin((degree) / 180 * 3.142);
        grenadeDirection.y = -cos((degree) / 180 * 3.142);
        D3DXVec2Normalize(&grenadeDirection, &grenadeDirection);
    }
    else if (degree > 90 || degree <= 180)
    {
        degree = degree - 90;
        degree = 0 - degree;
        grenadeDirection.x = sin((degree) / 180 * 3.142);
        grenadeDirection.y = -cos((degree) / 180 * 3.142);
        D3DXVec2Normalize(&grenadeDirection, &grenadeDirection);
    }
    grenadeVelocity = grenadeDirection * grenadeSpeed;

Grenade after reach ground

Grenade after a while

Source: Windows Questions C++

LEAVE A COMMENT