1.8.8 Create Smooth Armorstand Rotation

Discussion in 'Spigot Plugin Development' started by IronMan59, Mar 9, 2020.

  1. https://gyazo.com/7058686eff9df1da8f5b10ee2e5dafbd, this is what I mean by smooth rotation. My current code to rotate the armorstand is:
    Code (Text):
     //- Pickaxe Item
                            itemEnchanting.setArms(true);
                            itemEnchanting.setGravity(false);
                            itemEnchanting.setVisible(false);
                            itemEnchanting.setRightArmPose(new EulerAngle(4.6, 0, 0));
                            itemEnchanting.setItemInHand(e.getItemDrop().getItemStack());
                            new BukkitRunnable() {
                                int tick = 0;
                                @Override
                                public void run() {
                                    tick++;
                                    double t = ((double) tick%40) * Math.PI / 20;
                                    Vector v = new Vector(Math.cos(t), 0, Math.sin(t));
                                    v.multiply(.1);
                                    itemEnchanting.setVelocity(v);
                                    float yaw = itemEnchanting.getLocation().getYaw();
                                    yaw += 9;
                                    Location location = new Location(itemEnchanting.getWorld(), itemEnchanting.getLocation().getX(), itemEnchanting.getLocation().getY(), itemEnchanting.getLocation().getZ(), yaw, itemEnchanting.getLocation().getPitch());
                                    itemEnchanting.teleport(location.add(v));
                                }
                            }.runTaskTimer(vulcanPrisons, 1, 1);
    Any help would be appreciated I've been working on this for about a week now lol.
     
  2. So you need to get something like this: (right?)
    [​IMG]
    So you need to basically rotate an armor stand around an object like this:
    [​IMG]
     
  3. Yes that is correct but how would I do that and do that slightly faster than what you are doing
     
  4. drives_a_ford

    Moderator

    You can only ever set the location/position/rotation once a tick (20 times a second). If that's not granual enough for you, I'm afraid there's no "faster" option.
     
  5. The maximum smooth speed is 18 degrees/second (requires perfect positioning)
     
    • Useful Useful x 1
  6. How can I change my code to make it rotate 18 degrees/second?
     
  7. You would need to rotate by 18 degrees / 20 ticks to make a smooth rotation. Then its up to you to capture current rotation and simply add to that.
     
  8. You already are running this task every server tick, so like @drives_a_ford says, this is a smooth as it gets.
    You can rotate by any value. By default you are using "yaw += 9" so I believe that is 9 degrees, I don't think it is in radians.
    currently your code will rotate 9 degrees * 20(ticks per second) = 180 degrees a second, so a full rotation will take 2 seconds.
    That screen capture looks like it is turning 360 degrees a second so "yaw += 18" like @TSEngineer says.
    I am not actually sure which is going to end up looking smoother rotating the object faster or slower, but I suppose the choppiness is masked the faster it spins.
    So just change your your code to "yaw += 18", and if it is still choppy increase the value of 18 until you think it is acceptable.
     
  9. Please note that 18 degrees/second is maximum perfect smooth speed, everything above 18 but below 45 will also be looking smooth, but won't be perfectly smooth.