Solved Math.Pi

Discussion in 'Plugin Development' started by FloopThatGuy5, May 4, 2015.

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

    FloopThatGuy5

    I want it to spawn 4 minecarts go up and spin, does anyone know how I can use the code below todo that
    Code:
        if(cmd.getName().equalsIgnoreCase("swing")){
                if(sender instanceof BlockCommandSender){
                    Block cmdblock2 = ((BlockCommandSender) sender).getBlock();
                    World w2 = cmdblock2.getWorld();
                    Location loc1 = new Location(w2, 54.559, 92, -129.522);
                    Location loc2 = new Location(w2, 59.404, 92, -134.500);
                    Location loc3 = new Location(w2, 54.476, 92, -139.437);
                    Location loc4 = new Location(w2, 49.296, 92, -134.500);
                   
                   
                    final Minecart m1 = w2.spawn(loc1, Minecart.class);       
                    final Minecart m2 = w2.spawn(loc2, Minecart.class);
                    final Minecart m3 = w2.spawn(loc3, Minecart.class);
                    final Minecart m4 = w2.spawn(loc4, Minecart.class);
                   
               
                   
                     //  Vector vecCart1To = new Location(w2, 54, 92, -129).toVector();
                    //     final Vector vecCart1 = m1.getLocation().toVector().add(vecCart1To).normalize().multiply(new Vector(0, 2, 0)).setY(2.7D);
               
                     //    Location lT = m1.getLocation();
                    //     m1.getLocation().setYaw(90F);
                    //    m1.teleport(lT);
                //    final Location bLoc = new Location(w2, 54.634, 94, -134.700);
                //    final Bat bS = w2.spawn(bLoc, Bat.class);
                   
                //    bS.setAwake(false);
                   
            //        bS.setLeashHolder(m2);
            //        bS.setLeashHolder(m3);
                //    bS.setLeashHolder(m4);
            //         bS.setLeashHolder(m1);
                    new BukkitRunnable() {   
                       
                int counter = 0;
               double angle = 0.0D;
               double step = ((2 * Math.PI) / 220.0D); // 1 circle in 5 seconds
                double speed = -1.5D; // determines radius
                   
                    @Override
                public void run() {
                        m1.setVelocity(new Vector(Math.cos(angle) * speed, 0.0D, Math.sin(angle) * speed));
                    //    m2.setVelocity(new Vector(Math.cos(angle) * speed, 0.00D, Math.sin(angle) * speed));
                    //    m3.setVelocity(new Vector(Math.cos(angle) * speed, 0.00D, Math.sin(angle) * speed));
                    //    m4.setVelocity(new Vector(Math.cos(angle) * speed, 0.00D, Math.sin(angle) * speed));
    
                        angle += step;
                    if (++counter > 150) {
                       this.cancel(); // stop after 5 circles
    
               
             
                    }
                       
                    }
                    }.runTaskTimer(this, 20L, 1L);
                   
                    new BukkitRunnable() {   
                       
                            @Override
                        public void run() {
                                int counter = 0;
                               
                                m1.setVelocity(new Vector(0, 0.1, 0));
                            if (++counter > 150) {
                               this.cancel(); // stop after 5 circles
    
                       
                     
                            }
                               
                            }
                            }.runTaskTimer(this, 20L, 1L);
                }
            }
        
     
  2. You don't need Math.Pi.
    Just add 0.2 (for example) to the minecarts yaw (with teleportation), and run this code for (int) (360 / 0.2) times to get a full rotation.
     
  3. Offline

    FloopThatGuy5

    @FisheyLP but will a player still be able to get in the cart with teleportation? and thx
     
  4. I think he stays in the cart when you teleport it.
     
  5. Offline

    FloopThatGuy5

  6. Offline

    mine-care

Thread Status:
Not open for further replies.

Share This Page