fix(minecraft): correct gaze ray pitch direction

This commit is contained in:
Rin
2026-02-18 11:14:39 +08:00
committed by Neko Ayaka
parent e700676335
commit 1ecedb203b
2 changed files with 5 additions and 5 deletions
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
import { Vec3 } from 'vec3'
import { describe, expect, it } from 'vitest'
import { rayTraceBlockFromEntity } from './gaze'
@@ -22,7 +22,7 @@ describe('rayTraceBlockFromEntity', () => {
username: 'tester',
position: new Vec3(0, 64, 0),
yaw: 0,
pitch: Math.PI / 4,
pitch: -Math.PI / 4,
}
const result = rayTraceBlockFromEntity(bot, entity, { maxDistance: 8, step: 0.1 })
@@ -42,7 +42,7 @@ describe('rayTraceBlockFromEntity', () => {
username: 'tester',
position: new Vec3(0, 64, 0),
yaw: 0,
pitch: -Math.PI / 4,
pitch: Math.PI / 4,
}
const result = rayTraceBlockFromEntity(bot, entity, { maxDistance: 8, step: 0.1 })
@@ -24,8 +24,8 @@ export interface PlayerGazeResult {
function directionFromYawPitch(yaw: number, pitch: number): Vec3Like {
const x = -Math.sin(yaw) * Math.cos(pitch)
// In Minecraft, positive pitch means looking down (negative Y direction).
const y = -Math.sin(pitch)
// Mineflayer pitch convention: positive pitch looks up, negative pitch looks down.
const y = Math.sin(pitch)
const z = -Math.cos(yaw) * Math.cos(pitch)
return { x, y, z }
}