既に異なる方向で発射しているので、2つのコンポーネントによって定義された速度ベクトルがあると仮定しています(x, y)
。 JavaFXでは、このようなベクトルはPoint2D
で表すことができます。
public void fire() {
// the point at which you are shooting
Point2D target = ...
// the point from where you are shooting
Point2D source = ...
// the projectile speed per frame
double speed = ...
// velocity vector to be used to move
// the projectile at constant speed per frame
Point2D velocity = target.subtract(source).normalize().multiply(speed);
}
UPDATE:(角度から含まベクトル生成)
あなたがターゲットポイントを知っていない場合は、あなたが得ることができspeed
あなたは次の操作を行うことができ、発射の時に旅行したいを考えますあなたが撮影に使用する角度からのベクトル:
public void fire() {
double angleDegrees = ...
double angleRadians = Math.toRadians(angleDegrees);
// the point from where you are shooting
Point2D source = ...
// the projectile speed per frame
double speed = ...
Point2D shootingVector = new Point2D(Math.cos(angleRadians), Math.sin(angleRadians));
// velocity vector to be used to move
// the projectile at constant speed per frame
Point2D velocity = shootingVector.normalize().multiply(speed);
}
こんにちはAlmasB、私はベクトルの数学で完全な初心者です。私はサブのx、y座標を持っています。私は一定の角度(30,45,90など)で魚雷を発射したいと思います。このfire()メソッドであなたのスピードの入力を使って、魚雷が取る経路をどのように生成するのですか?あなたの助けに感謝! – user1104028
更新された回答をご覧ください。あなたはY軸を調整する必要があるかもしれません。なぜなら、グラフィックスでは、正のYが下がり、数学では正のYが上にあるからです。 – AlmasB
こんにちはAlmasBだから、VectorBrowserのNewBieである、私は発射体の角度とスピードを指定しているので、射撃ベクトルには射影体が従わなければならないXとYのインクリメンタルな動きが含まれていますか? (私は射影が続く必要があるx、yの点の配列を生成するために探しています)ありがとう! – user1104028