【发布时间】:2021-09-10 19:58:48
【问题描述】:
我正在编写一个模拟球运动的代码。我有一个 updateBall 函数,它每 100 毫秒运行一次以更新球的位置。
如何找出到达给定目标坐标所需的最小速度? 下面是相关代码,
ball.x = 0;
ball.y = 0;
targetX = 100;
targetY = 200;
friction = 0.03;
dx = targetX - ball.x;
dy = targetY - ball.y;
distance = sqrt(dx*dx + dy*dy);
velocity = ?;
// runs every 100ms
updateBall()
{
ball.x += velocity;
ball.y += velocity;
velocity -= friction;
}
【问题讨论】:
标签: math game-physics