Java 改变弹丸的速度

Java 改变弹丸的速度,java,plugins,minecraft,bukkit,Java,Plugins,Minecraft,Bukkit,我是bukkit插件开发的新手,我想知道如何改变雪球/任何其他投射物的速度。在我的代码中,当玩家与某个对象交互时,它会发射一个雪球,但我需要改变它的速度。我们将不胜感激 谢谢 代码: 现在你只需发射雪球射弹。必须向对象添加速度才能更改其速度。这是通过编辑对象本身来完成的 以下是您应该使用的基本大纲。我没有办法测试这一点,但它应该有助于为您指出正确的方向 Snowball snowball = player.launchProjectile(Snowball.class); // Get vec

我是bukkit插件开发的新手,我想知道如何改变雪球/任何其他投射物的速度。在我的代码中,当玩家与某个对象交互时,它会发射一个雪球,但我需要改变它的速度。我们将不胜感激

谢谢

代码:


现在你只需发射
雪球
射弹。必须向对象添加速度才能更改其速度。这是通过编辑对象本身来完成的

以下是您应该使用的基本大纲。我没有办法测试这一点,但它应该有助于为您指出正确的方向

Snowball snowball = player.launchProjectile(Snowball.class);

// Get vectors
Vector i = target.getLocation().toVector();
Vector j = snowball.getLocation().toVector();

// Perform the subtraction, then normalize
Vector r = i.subtract(j);
Vector v = r.normalize();

// then, actually set the speed, in this case, by a magnitude of four
Vector velocity = v.multiply(4);

// Then, set the velocity of the snowball but updating the 'default' velocity of the snowball
snowball.setVelocity(snowball.setVelocity(velocity));
这可以通过编写复合表达式来压缩:

Snowball snowball = player.launchProjectile(Snowball.class);

Vector velocity = (target.getLocation().toVector().subtract(snowball.getLocation().toVector()).normalize()).multiply(4);
snowball.setVelocity(snowball.setVelocity(velocity));

希望这有帮助

您需要提供一段代码,以便人们帮助您。您可以在此处找到代码:该代码不足。Snowball的代码在哪里,您可能会在那里找到setSpeed()和getSpeed()方法?我假设
Snowball
类是
Bukkit
投射物
类的派生。
Snowball snowball = player.launchProjectile(Snowball.class);

Vector velocity = (target.getLocation().toVector().subtract(snowball.getLocation().toVector()).normalize()).multiply(4);
snowball.setVelocity(snowball.setVelocity(velocity));