私は現在、Java LWJGLで3D一人称シューティングゲームを作っています。私は回って、世界の特定のポイントに向かって弾丸を動かしたい。私はY軸を弾くが、XとZは弾かないようにすることができました。弾丸をZ軸とX軸でどのように回転させてポイントに向かって動かすことができますか?ここで3次元空間の点に弾丸を移動する方法
は私の弾丸のクラスである:あなたが何をしたいか
package entities;
import org.lwjgl.util.vector.Vector3f;
import models.TexturedModel;
import renderEngine.DisplayManager;
import toolbox.MousePicker;
public class Bullet extends Entity{
private static Vector3f currentRay = new Vector3f();
private static final float RAY_RANGE = 600;
public static boolean reset = true;
public Bullet(TexturedModel model, Vector3f position, float rotX, float rotY, float rotZ, float scale) {
super(model, position, rotX, rotY, rotZ, scale);
}
public void move(Bullet b){
float distance = 2 * DisplayManager.getFrameTimeSeconds();
currentRay = MousePicker.calculateMouseRay();
Vector3f endPoint = MousePicker.getPointOnRay(currentRay, 10000);
//I want my Bullet to move towards the Vector3f endPoint
float zDistance = endPoint.z - this.getPosition().z;
float xDistance = endPoint.x - this.getPosition().x;
double angleToTurn = Math.toDegrees(Math.atan2(xDistance, zDistance));
this.setRotY((float)angleToTurn);
float dx = (float) (distance * Math.sin(Math.toRadians(super.getRotY())));
float dz = (float) (distance * Math.cos(Math.toRadians(super.getRotY())));
super.increasePosition(dx, 0, dz);
}
}
に向かって移動するようにする
とあなた
super.increasePosition(speed.x, speed.y, speed.z);
は、あなたが回転し3つの角度を取得してもよろしいでしょうか? おそらく、瞬時速度を次のように設定することも考えられます: targetPosition.sub(bulletPossition).normalize()。scalarMult(bullet.maxSpeed) そして、この瞬時速度を各更新ループの位置に加えます。 Vector3fで提供されているものとまったく同じものではありません。 – PignictargetPostionとは何ですか? – Disser
申し訳ありませんが、エンドポイントと呼ばれるポイントです – Pignic