二维波矢
所以我试图让玩家发射一颗子弹,以波浪状的方式射向鼠标。我可以让子弹以波浪状移动(尽管不是我预测的那样),但不能朝鼠标移动。
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
}
So I'm trying to make the player shoot a bullet that goes towards the mouse in a wavey pattern. I can get the bullet to move in a wavey pattern (albeit not really how I predicted), but not towards the mouse.
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;
}
Right now the speed isn't much of a concern, that shouldn't be too much of a problem once I have this figured out. I do get some angle change, but it seems to be reversed and only 1/8th a circle.
I'm probably miscalculating something somewhere. I just kind of learned about wave vectors.
I've tried a few other things, such as 1 dimensional travelling waves and another thing involving adjusting a normal sine wave by vec
. Which had more or less the same result.
Thanks!
EDIT:
vec
is the displacement from the player's location to the mouse click location. The return is a new vector that is adjusted to follow a wave pattern, BulletFun::sine
is called each time the bullet receives and update.
The setup is something like this:
void Bullet::update() {
_velocity = BulletFun::sine(_displacement);
_location.add(_velocity); // add is a property of Tuple
// which Vector2 and Point2 inherit
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在伪代码中,您需要做的是:
应该在传统坐标系中计算波矢量,然后将其旋转到方向矢量的局部坐标系(其中方向矢量是局部x轴),然后相对于您想要的波束原点位置或其他位置平移波矢量...
这将产生一个非常类似于
In pseudocode, what you need to do is the following:
That should compute the wave vector in a traditional coordinate frame, and then rotate it to the local coordinate frame of the direction vector (where the direction vector is the local x-axis), and then translate the wave vector relative to your desired origin position of the wave beam or whatever...
This will result in a function very similar to