#Spawning particles in a line

1 messages ยท Page 1 of 1 (latest)

final coyote
#

Let's say that my entity attack the armor stand, I assume I would detect the location of my entity and the armor stand as vector points. Now, how do I draw a line using particles and make it constant?

#

someone said to iterate those points, but I'm not fully sure if I understood what it meant without some examples

green lotus
final coyote
#

I should've worded it better

green lotus
#
function distance(vector1, vector2) {
    return Math.sqrt(Math.abs(vector1.x - vector2.x)**2 + Math.abs(vector1.y - vector2.y)**2 + Math.abs(vector1.z - vector2.z)**2)
}

function line(vector1, vector2, step2 = 1) {
    let dist = distance(vector1, vector2)
    let step = {
      x: (vector2.x - vector1.x) / (dist || 1),
      y: (vector2.y - vector1.y) / (dist || 1),
      z: (vector2.z - vector1.z) / (dist || 1)
    }
    let list = []
    for (let i = 0; i < dist; i += step2) {
      list.push({
        x: vector1.x + i*step.x,
        y: vector1.y + i*step.y,
        z: vector1.z + i*step.z
      })
    }
    return list
}
final coyote
green lotus
void willow
#
function line(position1, position2, step = 0.1) {
    const dx = position2.x - position1.x;
    const dy = position2.y - position1.y;
    const dz = position2.z - position1.z;

    const distance = Math.sqrt(dx * dx + dy * dy + dz * dz);
    const steps = Math.ceil(distance / step);

    for (let i = 0; i <= steps; i++) {
        const t = i / steps;
        const x = position1.x + t * dx;
        const y = position1.y + t * dy;
        const z = position1.z + t * dz;

        return { x, y, z };
    }
}

const loc1 = { x: 0, y: 0, z: 0 };
const loc2 = { x: 10, y: 20, z: 0 };
const location = line(loc1, loc2);
dimension.spawnParticle('minecraft:redstone_wire_dust_particle', location);

My goofy ahh will give you this.

final coyote
#

This code works wondrous! Now all that's left to do is to find out how I will make this particle spawn higher or at head location and then make it constantly update each every 2 ticks or so

if(source.typeId === 'felixchats_l4d2:spitter'){
        function distance(vector1, vector2) {
            return Math.sqrt(Math.abs(vector1.x - vector2.x)**2 + Math.abs(vector1.y - vector2.y)**2 + Math.abs(vector1.z - vector2.z)**2)
        }
        
        function line(vector1, vector2, step2 = 1) {
            let dist = distance(vector1, vector2)
            let step = {
              x: (vector2.x - vector1.x) / (dist || 1),
              y: (vector2.y - vector1.y) / (dist || 1),
              z: (vector2.z - vector1.z) / (dist || 1)
            }
            let list = []
            for (let i = 0; i < dist; i += step2) {
              list.push({
                x: vector1.x + i*step.x,
                y: vector1.y + i*step.y,
                z: vector1.z + i*step.z
              })
            }
            return list
        }

        for (let loc of line(source.location, victim.location, 0.3)) {
            source.dimension.spawnParticle('minecraft:villager_happy', loc)
        }
    }```
void willow
#

just use Entity.getHeadLocation()

final coyote
#

now that I think about it, this might be something I need to use in a runTimeout function

void willow
final coyote
void willow
#

then just replace it with the head location....

final coyote
#

let me see, I'll have to check which one it is

#

I found it, it was entity1