#Spawning particles in a line
1 messages ยท Page 1 of 1 (latest)
someone said to iterate those points, but I'm not fully sure if I understood what it meant without some examples
To clarify: do you need to connect entities with a straight line of particles?
yes, that is what I'm trying to do very much so
I should've worded it better
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
}
I see, I shall learn about this more thoroughly by looking at this example
thank you very much ๐๐๐
for (let loc of line(entity1.location, entity2.location, 0.3)) {
entity1.dimension.spawnParticle('minecraft:villager_happy', loc)
}
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.
this will be helpful too incase I need more examples, thank you very much too ๐๐ ๐
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)
}
}```
does it only update once?
just use Entity.getHeadLocation()
and that would replace which part?
now that I think about it, this might be something I need to use in a runTimeout function
It depends, does it come from the head of the one who hit or the one who get hit
it would be from the source, that is
where did you put the location of the source in the function? vector1 or vector2
then just replace it with the head location....