Alright so im using Raylib.h and got stuck in this code for a while now. I want to have a smooth animating movement of the velocity vector of the ball from one point to another. Basically The principle is to drag at any point on the screen and the ball will go opposite direction to that like a bow? But it goes at instant from one point to another which i dont want
typedef struct Ball {
Vector2 position;
Vector2 speed;
float radius;
bool active;
} Ball;
int main (void)
{
const int width = 1080;
const int height = 720;
static Ball ball = {0};
Vector2 pos1;
Vector2 pos2;
Vector2 posChange;
SetTargetFPS(60);
InitWindow(width,height,"Midny is sad frfr");
Texture2D background = LoadTexture("green_checker.png");
ball.position = (Vector2){(width)/4, height-80};
ball.speed = (Vector2){0 , 0};
ball.radius = 8;
ball.active = false;
while(!(WindowShouldClose()))
{
if(IsMouseButtonPressed(MOUSE_BUTTON_LEFT)){
pos1 = GetMousePosition();
}
if(IsMouseButtonDown(MOUSE_BUTTON_LEFT)){
pos2 = GetMousePosition();
posChange = Vector2Subtract(pos2,pos1);
}
if(IsMouseButtonReleased(MOUSE_BUTTON_LEFT)){
Vector2 DirectionVelocityVector = Vector2Negate(posChange);
//float distance = Vector2Distance(posChange,pos1);
ball.active = true;
//Vector2 target = Vector2MoveTowards(ball.position,DirectionVelocityVector,distance/10000);
ball.speed = (Vector2) { DirectionVelocityVector.x, DirectionVelocityVector.y};
Vector2 movementThisFrame = Vector2Scale(ball.speed,GetFrameTime()*200);
ball.position = Vector2Add(ball.position,movementThisFrame);
if(ball.active){
ball.position.x = ball.position.x + ball.speed.x;
ball.position.y = ball.position.y + ball.speed.y;
}
}
BeginDrawing();
ClearBackground(RAYWHITE);
DrawTexture(background,0,0,WHITE);
DrawCircleV(ball.position,ball.radius,WHITE);
EndDrawing();
}
}
I was expecting a smooth animated movement but it doesnt expect to happen ig.. It moves at instant from one point to another? Is there any possible way to fix this thank you