Plethora Peripherals

Plethora Peripherals

3M Downloads

Lasers fired from turtles originate a block lower than they should when pitch is 180

WindClan opened this issue ยท 4 comments

commented

Exactly what the title says

commented

Eve's suggestion is to perform a single-step raycast to find where the laser leaves the block, then add a little extra offset along the ray

commented

You probably don't need to ray trace - just project it ~0.7 blocks away from the middle of the turtle.

commented
local laser = peripheral.find("plethora:laser")
laser.fire(0,180,5) --fire from below the turtle

2024-03-29_00 59 49
as i said, exactly as the title says

commented

So this happens from pitch angles 61 to 180 due to this logic (specifically line 66):

// Offset positions to be around the edge of the manipulator. Avoids breaking the manipulator and the
// block below/above in most cases.
// Also offset to be just above/below the manipulator, depending on the pitch.
val offset = if (pitch < -60) {
Vec3d(0.0, 0.5 + vOff, 0.0)
} else if (pitch > 60) {
Vec3d(0.0, -0.5 - vOff, 0.0)
} else {
// The laser is 0.25 wide, the offset from the centre is 0.5.
val hOff = 0.9
val length = sqrt(motionX * motionX + motionZ * motionZ)
Vec3d(motionX / length * hOff, 0.0, motionZ / length * hOff)
}
laser.setPosition(pos.add(offset))

Seeing that condition you'd then expect that it's possible to launch the projectile a block above the turtle, but it's never reached due to Utils.mod always coercing values to be positive (used to normalize pitch):

/**
* Take modulo for double numbers according to lua math, and return a double result.
*
* @param lhs Left-hand-side of the modulo.
* @param rhs Right-hand-side of the modulo.
* @return double value for the result of the modulo,
* using lua's rules for modulo
*/
public static double mod(double lhs, double rhs) {
double mod = lhs % rhs;
return mod * rhs < 0 ? mod + rhs : mod;
}
/**
* Normalise an angle between -180 and 180.
*
* @param angle The angle to normalise.
* @return The normalised angle.
*/
public static double normaliseAngle(double angle) {
angle = mod(angle, 360);
if (angle > 180) angle -= 360;
return angle;
}

working on a fix for it rn that better handles the laser placement