Bullets hit, but they look like they go elsewhere

Discussion in 'Plugin Development' started by ZP18, Aug 29, 2015.

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

    ZP18

    I am making a gun plugin, the bullets are eggs, shooting works, but when it shoots it isn't always near the crosshair, sometimes the eggs look like they hit directly below you, but the still hurt entities in your crosshair. I don't like this because it is hard to adjust your aim. here is my Gun Class where I have the shoot function:
    Code:java
    1.  
    2. package zplugin.zguns.guns;
    3.  
    4. import org.bukkit.Material;
    5. import org.bukkit.entity.Egg;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.inventory.ItemStack;
    8. import org.bukkit.util.Vector;
    9.  
    10. import java.util.ArrayList;
    11. import java.util.HashMap;
    12. import java.util.List;
    13.  
    14. @SuppressWarnings("unused")
    15. public class Gun {
    16.  
    17. public static HashMap<Egg, Gun> bullets = new HashMap<>();
    18.  
    19. private GunType gunType;
    20. private String name;
    21.  
    22. private double damage;
    23. private double accuracy;
    24. private double speed;
    25.  
    26. public Gun(GunType gunType, String name) {
    27. this.gunType = gunType;
    28. this.name = name;
    29.  
    30. damage = gunType.getDamage();
    31. accuracy = gunType.getAccuracy();
    32. speed = gunType.getSpeed();
    33. }
    34.  
    35. public double getDamage() {
    36. return damage;
    37. }
    38.  
    39. public void setDamage(double damage) {
    40. this.damage = damage;
    41. }
    42.  
    43. public double getAccuracy() {
    44. return accuracy;
    45. }
    46.  
    47. public void setAccuracy(double accuracy) {
    48. this.accuracy = accuracy;
    49. }
    50.  
    51. public double getSpeed() {
    52. return speed;
    53. }
    54.  
    55. public void setSpeed(double speed) {
    56. this.speed = speed;
    57. }
    58.  
    59. public GunType getGunType() {
    60. return gunType;
    61. }
    62.  
    63. public void shoot(Player player) {
    64.  
    65. double randX, randY, randZ;
    66. randX = Math.random() * accuracy;
    67. randY = Math.random() * accuracy;
    68. randZ = Math.random() * accuracy;
    69.  
    70. Egg bullet = player.getWorld().spawn(player.getEyeLocation(), Egg.class);
    71. Vector velocity = new Vector().setX(randX).setY(randY).setZ(randZ);
    72. velocity.add(player.getLocation().getDirection().multiply(speed));
    73. bullet.setVelocity(velocity);
    74. bullet.setShooter(player);
    75. gunType.setOwner(player);
    76. bullets.put(bullet, this);
    77.  
    78. }
    79.  
    80. public static List<Material> getGunItems() {
    81. List<Material> list = new ArrayList<>();
    82. list.add(Material.WOOD_AXE); // P250 (PISTOL)
    83. list.add(Material.STONE_AXE); // UMP45 (SHOTGUN)
    84. list.add(Material.IRON_AXE); // M60 (MACHINE GUN)
    85. list.add(Material.GOLD_AXE); // SCAR-20 (SNIPER RIFLE)
    86. list.add(Material.DIAMOND_AXE); // AK-47 (RIFLE)
    87.  
    88. return list;
    89. }
    90.  
    91. public static boolean isGun(ItemStack itemStack) {
    92. for (Material material : getGunItems()) {
    93. if (itemStack.getType().equals(material)) {
    94. return true;
    95. }
    96. }
    97. return false;
    98. }
    99.  
    100. public static Gun getGunType(ItemStack itemStack) {
    101. if (itemStack.getType() == Material.WOOD_AXE) {
    102. return new P250();
    103. } else if(itemStack.getType() == Material.STONE_AXE) {
    104. return new UMP45();
    105. } else if(itemStack.getType() == Material.IRON_AXE) {
    106. return new M60();
    107. } else if(itemStack.getType() == Material.GOLD_AXE) {
    108. return new SCAR20();
    109. } else {
    110. return new AK47();
    111. }
    112. }
    113.  
    114. }
    115.  


    and here is my GunType Enum class:
    Code:java
    1.  
    2. package zplugin.zguns.guns;
    3.  
    4. import org.bukkit.entity.Player;
    5.  
    6. @SuppressWarnings("unused")
    7. public enum GunType {
    8.  
    9. PISTOL(2, 0.1, 10), RIFLE(1, 0.1, 15), SHOTGUN(2, 0.1, 12), SNIPER_RIFLE(10, 0.01, 13), MACHINE_GUN(3, 0.1, 11);
    10.  
    11. private double damage;
    12. private double accuracy;
    13. private double speed;
    14. private Player owner;
    15.  
    16. GunType(double damage, double accuracy, double speed) {
    17. this.damage = damage;
    18. this.accuracy = accuracy;
    19. this.speed = speed;
    20. }
    21.  
    22. public double getDamage() {
    23. return damage;
    24. }
    25.  
    26. public double getAccuracy() {
    27. return accuracy;
    28. }
    29.  
    30. public double getSpeed() {
    31. return speed;
    32. }
    33.  
    34. public Player getOwner() {
    35. return owner;
    36. }
    37.  
    38. public void setOwner(Player player) {
    39. owner = player;
    40. }
    41.  
    42. }
    43.  
     
  2. Offline

    MOMOTHEREAL

    //Offtopic...
    Isn't the UMP a SubMachine Gun? :}
     
  3. Offline

    ZP18

    I don't even know man, I don't care about that right now tho
     
Thread Status:
Not open for further replies.

Share This Page