Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
WindClan opened this issue Mar 29, 2024 · 4 comments · May be fixed by #95
Open

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

WindClan opened this issue Mar 29, 2024 · 4 comments · May be fixed by #95
Assignees
Labels
bug Something isn't working

Comments

@WindClan
Copy link

Exactly what the title says

@WindClan
Copy link
Author

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

@hugeblank hugeblank self-assigned this Mar 29, 2024
@hugeblank
Copy link
Contributor

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

@Lemmmy
Copy link
Member

Lemmmy commented Mar 29, 2024

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

@Lemmmy Lemmmy added the bug Something isn't working label Mar 29, 2024
@SquidDev
Copy link
Contributor

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

hugeblank added a commit that referenced this issue Apr 3, 2024
@hugeblank hugeblank linked a pull request Apr 3, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants