所以我试图让玩家射出一颗以波浪状射向鼠标的子弹。我可以让子弹以波浪状移动(尽管不是我预测的那样),但不能朝着鼠标移动。
Vector2 BulletFun::sine(Vector2 vec) {
float w = (2 * PI) / 1000; // Where 1000 is the period
float waveNum = (2 * PI) / 5; // Where 5 is the wavelength
Vector2 k(0.0F, waveNum);
float t = k.dot(vec) - (w * _time);
float x = 5 * cos(t); // Where 5 is the amplitude
float y = 5 * sin(t);
Vector2 result(x, y);
return result;
}
现在速度不是什么大问题,一旦我弄清楚了,这应该不是太大的问题。我确实得到了一些角度变化,但它似乎是颠倒的,只有 1/8 圈。
我可能在某个地方误算了一些东西。我只是了解了波向量。
我尝试了其他一些事情,例如一维行波和另一件涉及调整正常正弦波的事情vec
。结果或多或少相同。
谢谢!
编辑:
vec
是从玩家位置到鼠标点击位置的位移。返回是一个新的向量,它被调整为遵循波浪模式,BulletFun::sine
每次子弹接收和更新时都会被调用。
设置是这样的:
void Bullet::update() {
_velocity = BulletFun::sine(_displacement);
_location.add(_velocity); // add is a property of Tuple
// which Vector2 and Point2 inherit
}