Solved Vectors won't work below y64, I dont know why

Discussion in 'Plugin Development' started by ShadowLAX, Aug 11, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    ShadowLAX

    Hey bukkit, I'm having a problem with vectors. When I use my plugin at about y64 it works fine,
    but anything below that it shoves the player spastically sideways :S I don't know if it is my code, it is then I will be glad to show you. thanks!
     
  2. Offline

    Shinxs

    whats your code?
     
  3. Offline

    ShadowLAX

    Shinxs
    Code:java
    1. import org.bukkit.Bukkit;
    2. import org.bukkit.ChatColor;
    3. import org.bukkit.Color;
    4. import org.bukkit.FireworkEffect;
    5. import org.bukkit.FireworkEffect.Type;
    6. import org.bukkit.Location;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandExecutor;
    9. import org.bukkit.command.CommandSender;
    10. import org.bukkit.entity.EntityType;
    11. import org.bukkit.entity.Firework;
    12. import org.bukkit.entity.Player;
    13. import org.bukkit.inventory.meta.FireworkMeta;
    14. import org.bukkit.util.Vector;
    15.  
    16. public class BootExecutor implements CommandExecutor {
    17.  
    18. public Main plugin;
    19. public int counter;
    20.  
    21. public BootExecutor(Main instance) {
    22. plugin = instance;
    23. }
    24.  
    25. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    26. if (cmd.getName().equalsIgnoreCase("boot")) {
    27. if (sender instanceof Player) {
    28. final Player player = (Player) sender;
    29. if (player.hasPermission("punicements.boot")) {
    30. if (args.length > 0) {
    31. final Player target = Bukkit.getServer().getPlayer(args[0]);
    32. if (target != null) {
    33. if (target.getName() == player.getName()) {
    34. if (args.length > 1) {
    35. String message = "";
    36. for (int i = 1; i < args.length; ++i) {
    37. message += args[I] + " ";[/I]
    38. [I] }[/I]
    39. [I] final String mess = message;[/I]
    40. [I] Location tloc = target.getLocation();[/I]
    41. [I] Firework fw = (Firework) target.getWorld().spawnEntity(player.getLocation(), EntityType.FIREWORK);[/I]
    42. [I] FireworkMeta fwm = fw.getFireworkMeta();[/I]
    43. [I] FireworkEffect effect = FireworkEffect.builder().flicker(true).withColor(Color.fromRGB(255, 0, 0)).withFade(Color.fromRGB(0, 255, 0)).with(Type.BURST).trail(true).build();[/I]
    44. [I] fwm.addEffect(effect);[/I]
    45. [I] int power = 1;[/I]
    46. [I] fwm.setPower(power);[/I]
    47. [I] fw.setFireworkMeta(fwm);[/I]
    48. [I] target.setVelocity(new Vector(tloc.getX(), 2.2 ,tloc.getZ()));[/I]
    49. [I] counter = Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {[/I]
    50. [I] public void run() {[/I]
    51. [I] target.kickPlayer(ChatColor.RED + "You were kicked by " + player.getName() + " for " + mess);[/I]
    52. [I] }[/I]
    53. [I] }, 30L);[/I]
    54. [I] player.sendMessage(ChatColor.GREEN + "Player " + target.getName() + " has been kicked for " + message);[/I]
    55. [I] } else {[/I]
    56. [I] player.sendMessage(ChatColor.RED + "You must specify a reason!");[/I]
    57. [I] }[/I]
    58. [I] } else {[/I]
    59. [I] player.sendMessage(ChatColor.RED + "You can't boot yourself, don't even try");[/I]
    60. [I] }[/I]
    61. [I] } else {[/I]
    62. [I] player.sendMessage(ChatColor.RED + "Can't find player " + args[0] + "!");[/I]
    63. [I] }[/I]
    64. [I] } else {[/I]
    65. [I] player.sendMessage(ChatColor.RED + "Usage: /boot <player> [reason]");[/I]
    66. [I] }[/I]
    67.  
    68. [I] } else {[/I]
    69. [I] player.sendMessage(ChatColor.RED + "You don't have access to this command!");[/I]
    70. [I] }[/I]
    71. [I] } else {[/I]
    72. [I] sender.sendMessage("You must be a player to use this command!");[/I]
    73. [I] }[/I]
    74. [I] }[/I]
    75. [I] return true;[/I]
    76. [I] }[/I]
    77. [I]};[/I]
     
  4. Offline

    Shinxs

    ShadowLAX
    Code:
    target.setVelocity(new Vector(tloc.getX(), 2.2 ,tloc.getZ()));
    is this where you set the velocity thats going wrong?
     
  5. Offline

    ShadowLAX

    Shinxs yes, that sets the velocity of the target. Also, I get error messages in console:
    [WARNING] ShadowLAX moved too quickly! 0.0,0.0,0.0 (594.0462977999007, 2.077600040435791, 352.3791471060997)
     
  6. Offline

    Shinxs

    first of that not an error it is a warning. thats cuz your moving to quickly as it says but don't worry.

    you should try this:
    Code:
    target.setVelocity(target.getLocation.getDirection.add(new Vector(0, 2.2, 0)).multiply(any number).normalize())
    i don't think normalize is needed i only use it cuz sometime it works better ;)
     
  7. Offline

    ShadowLAX

    Shinxs I know its not an "official" error, but when it spams my console with it I call it an error :p Anyway thanks, I will go try it!
     
  8. Offline

    Shinxs

    reply here if it works :)

    try this for the "Error" :D http://dev.bukkit.org/bukkit-plugins/disable-moving-too-quickly/

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  9. Offline

    ShadowLAX

    Shinxs It works somewhat, but it wont go past a few blocks in the air no matter what I change. :(
     
  10. Offline

    blablubbabc

    To prevent the "player moed to fast messages": just make sure the vectors length is smaller then 10 by normalizing it to length 1 and bringing it to the wanted size (vector.normalize().multiply(size))
     
  11. Offline

    Shinxs

    maybe remove normalize and then edit 2.2 lets see what that does
     
  12. Offline

    ShadowLAX

    blablubbabc Thanks!

    Shinxs Thanks, that seemed to work! :D, one more thing though, with the getDirection() they move forward a bit too, is there anyway to not use the getDirection() or cancel the forward movement?
     
  13. Offline

    Shinxs

    i think us new vector(0, [any number], 0) and don't multiply it
     
  14. Offline

    ShadowLAX

  15. Offline

    Shinxs

    so it worked?
     
  16. Offline

    ShadowLAX

  17. Offline

    Shinxs

    k cool
     
  18. Offline

    Plo124

    Shinxs
    Is 0x10 still 0? You can multiply it, but its better to just increase the Vector size
     
  19. Offline

    Shinxs

    yes it's still 0
     
  20. Offline

    fromgate

    Why vector must be smaller than 10? Not 20? Not 15? I tried normalized vectors — works for me, but... why? $)
     
  21. Offline

    blablubbabc

    Maybe Minecraft can't handle fast speeds (collision detection etc..).. but I don't know either why exactly 10
     
  22. Offline

    fromgate

    What is the measurement of velocity? Is velocity 0,1,0 means a one block up per one second?
     
Thread Status:
Not open for further replies.

Share This Page