所以我试图让玩家发射一颗子弹,以波动的方式朝向鼠标。我可以让子弹以波浪形式移动(尽管不是我预测的),但不是朝着鼠标移动。二维波矢
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的一圈。
我可能错误地计算某个地方。我只是了解波矢。
我试过其他一些东西,比如1维行波和另一件涉及调整正常正弦波的东西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
}
很难看出来你真的想要什么功能。函数给出的'vec'的值是多少?它的返回值应该代表什么? – leftaroundabout 2012-02-07 21:56:51