Files

55 lines
1.8 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# pirt3.js — runProjectile() (satır 166)
[← pirt3.js](index.md) · [← Master](../../wiki.md)
Parça 1/6 · [sonraki](runProjectile-2.md)
```javascript
function runProjectile(c) {
var world = c.getWorld();
var shooterUUID = c.getValue("shooterUUID");
var pos = c.getValue("projPos");
var look = c.getValue("projLook");
var projTick = c.getValue("projTick");
var speed = SPELL_CONFIG.PROJECTILE_SPEED;
var nextPos = pos.add(look.multiply(speed));
var distance = pos.subtract(nextPos).length();
var steps = Math.floor(distance / 0.15);
if (steps < 1) steps = 1;
for (var i = 0; i <= steps; i++) {
var t = i / steps;
var p = pos.add(look.multiply(speed * t));
spawnSpellParticle(world, SPELL_CONFIG.PARTICLE_LASER_1, p.x, p.y, p.z, 3, 0.28, 0.28, 0.28, 0.05);
spawnSpellParticle(world, SPELL_CONFIG.PARTICLE_LASER_2, p.x, p.y, p.z, 2, 0.25, 0.25, 0.25, 0.02);
if (Math.random() < 0.6) {
spawnSpellParticle(world, SPELL_CONFIG.PARTICLE_LASER_3, p.x, p.y, p.z, 2, 0.22, 0.22, 0.22, 0.02);
}
}
var ray = world.rayTrace(pos.x, pos.y, pos.z, nextPos.x, nextPos.y, nextPos.z);
var didHit = false;
var hitPos = null;
if (!ray.isMissed()) {
if (ray.isEntity()) {
var hitEntity = ray.getEntity();
if (hitEntity !== null && hitEntity.getUniqueId() !== shooterUUID) {
didHit = true;
hitPos = ray.getHitPosition();
}
} else if (ray.isBlock()) {
didHit = true;
hitPos = ray.getHitPosition();
}
}
if (didHit && hitPos !== null) {
var cx = Math.floor(hitPos.x);
var cy = Math.floor(hitPos.y);
var cz = Math.floor(hitPos.z);
```