Make particle cape rotate respect to the player

Discussion in 'Plugin Development' started by herobine117, Nov 7, 2019.

  1. Offline

    herobine117

    How can I make the cape "follow" the player?

    Current code:

    Code:
    package com.dec0de.xcosmetics.api.capes;
    
    import org.bukkit.Location;
    import org.bukkit.Particle;
    import org.bukkit.entity.Player;
    import org.bukkit.util.Vector;
    
    public class Test {
    
        public static Vector perp(Vector onto, Vector u) {
            return u.clone().subtract(proj(onto, u));
        }
        public static Vector proj(Vector onto, Vector u) {
            return onto.clone().multiply(onto.dot(u) / onto.lengthSquared());
        }
        public static void drawInPlane(Player p) {
    
            double twopi = 2 * Math.PI;
            double times = 1 * twopi;
            double division = twopi / 100;
            double radius = -0.5;
        
            Location c = p.getEyeLocation();
            Vector nv = c.getDirection().normalize();
        
            double nx = radius * nv.getX() + c.getX();
            double ny = radius * nv.getY() + c.getY();
            double nz = radius * nv.getZ() + c.getZ();
        
            Vector ya = perp(nv, new Vector(0, 1, 0)).normalize();
            Vector xa = ya.getCrossProduct(nv).normalize();
        
            for (double theta = 0; theta < times; theta += division) {
    
                double xb = 0;
                double yb = 0;
                
                double xi = xa.getX() * xb + ya.getX() * yb;
                double yi = xa.getY() * xb + ya.getY() * yb;
                double zi = xa.getZ() * xb + ya.getZ() * yb;
                
                double x = xi + nx;
                double y = yi + ny;
                double z = zi + nz;
            
                // I know... This is probably not the best way to create particles.
            
                p.spawnParticle(Particle.TOTEM, new Location(c.getWorld(), x+0.3, y-0.1, z), 1, 0, 0, 0, 0);
                p.spawnParticle(Particle.TOTEM, new Location(c.getWorld(), x+0.2, y-0.1, z), 1, 0, 0, 0, 0);
                p.spawnParticle(Particle.TOTEM, new Location(c.getWorld(), x+0.1, y-0.1, z), 1, 0, 0, 0, 0);
                p.spawnParticle(Particle.TOTEM, new Location(c.getWorld(), x, y-0.1, z), 1, 0, 0, 0, 0);
                p.spawnParticle(Particle.TOTEM, new Location(c.getWorld(), x-0.3, y-0.1, z), 1, 0, 0, 0, 0);
                p.spawnParticle(Particle.TOTEM, new Location(c.getWorld(), x-0.2, y-0.1, z), 1, 0, 0, 0, 0);
                p.spawnParticle(Particle.TOTEM, new Location(c.getWorld(), x-0.1, y-0.1, z), 1, 0, 0, 0, 0);
            
                p.spawnParticle(Particle.TOTEM, new Location(c.getWorld(), x+0.3, y-0.3, z), 1, 0, 0, 0, 0);
                p.spawnParticle(Particle.TOTEM, new Location(c.getWorld(), x+0.2, y-0.3, z), 1, 0, 0, 0, 0);
                p.spawnParticle(Particle.TOTEM, new Location(c.getWorld(), x+0.1, y-0.3, z), 1, 0, 0, 0, 0);
                p.spawnParticle(Particle.TOTEM, new Location(c.getWorld(), x, y-0.3, z), 1, 0, 0, 0, 0);
                p.spawnParticle(Particle.TOTEM, new Location(c.getWorld(), x-0.3, y-0.3, z), 1, 0, 0, 0, 0);
                p.spawnParticle(Particle.TOTEM, new Location(c.getWorld(), x-0.2, y-0.3, z), 1, 0, 0, 0, 0);
                p.spawnParticle(Particle.TOTEM, new Location(c.getWorld(), x-0.1, y-0.3, z), 1, 0, 0, 0, 0);
            
                p.spawnParticle(Particle.TOTEM, new Location(c.getWorld(), x+0.3, y-0.6, z), 1, 0, 0, 0, 0);
                p.spawnParticle(Particle.TOTEM, new Location(c.getWorld(), x+0.2, y-0.6, z), 1, 0, 0, 0, 0);
                p.spawnParticle(Particle.TOTEM, new Location(c.getWorld(), x+0.1, y-0.6, z), 1, 0, 0, 0, 0);
                p.spawnParticle(Particle.TOTEM, new Location(c.getWorld(), x, y-0.6, z), 1, 0, 0, 0, 0);
                p.spawnParticle(Particle.TOTEM, new Location(c.getWorld(), x-0.3, y-0.6, z), 1, 0, 0, 0, 0);
                p.spawnParticle(Particle.TOTEM, new Location(c.getWorld(), x-0.2, y-0.6, z), 1, 0, 0, 0, 0);
                p.spawnParticle(Particle.TOTEM, new Location(c.getWorld(), x-0.1, y-0.6, z), 1, 0, 0, 0, 0);
            
                p.spawnParticle(Particle.TOTEM, new Location(c.getWorld(), x+0.3, y-0.9, z), 1, 0, 0, 0, 0);
                p.spawnParticle(Particle.TOTEM, new Location(c.getWorld(), x+0.2, y-0.9, z), 1, 0, 0, 0, 0);
                p.spawnParticle(Particle.TOTEM, new Location(c.getWorld(), x+0.1, y-0.9, z), 1, 0, 0, 0, 0);
                p.spawnParticle(Particle.TOTEM, new Location(c.getWorld(), x, y-0.9, z), 1, 0, 0, 0, 0);
                p.spawnParticle(Particle.TOTEM, new Location(c.getWorld(), x-0.3, y-0.9, z), 1, 0, 0, 0, 0);
                p.spawnParticle(Particle.TOTEM, new Location(c.getWorld(), x-0.2, y-0.9, z), 1, 0, 0, 0, 0);
                p.spawnParticle(Particle.TOTEM, new Location(c.getWorld(), x-0.1, y-0.9, z), 1, 0, 0, 0, 0);
            
                p.spawnParticle(Particle.TOTEM, new Location(c.getWorld(), x+0.3, y-1.2, z), 1, 0, 0, 0, 0);
                p.spawnParticle(Particle.TOTEM, new Location(c.getWorld(), x+0.2, y-1.2, z), 1, 0, 0, 0, 0);
                p.spawnParticle(Particle.TOTEM, new Location(c.getWorld(), x+0.1, y-1.2, z), 1, 0, 0, 0, 0);
                p.spawnParticle(Particle.TOTEM, new Location(c.getWorld(), x, y-1.2, z), 1, 0, 0, 0, 0);
                p.spawnParticle(Particle.TOTEM, new Location(c.getWorld(), x-0.3, y-1.2, z), 1, 0, 0, 0, 0);
                p.spawnParticle(Particle.TOTEM, new Location(c.getWorld(), x-0.2, y-1.2, z), 1, 0, 0, 0, 0);
                p.spawnParticle(Particle.TOTEM, new Location(c.getWorld(), x-0.1, y-1.2, z), 1, 0, 0, 0, 0);
            }
        }
    }
    
    Results:


    [​IMG]

    [​IMG]
     
  2. Online

    timtower Moderator Moderator

    @herobine117 Your offsets are relative the world, you need to rotate them to match the direction of the player.
     
  3. Offline

    herobine117

    Yeah... But I dont know how
     
  4. Online

    timtower Moderator Moderator

  5. Offline

    herobine117

  6. Online

    timtower Moderator Moderator

    Will see if I can get to that today.

    EDIT: Couldn't figure it out, Minecraft does other things then the software I normally work with.
     
    Last edited: Nov 10, 2019

Share This Page