mirror of
https://github.com/2revoemag/PSF-BotServer.git
synced 2026-07-16 00:44:43 +00:00
fix: Add vertical (pitch) targeting for tracers
Calculate pitch angle using atan2(dz, horizontalDist) so bots can aim up/down at targets on different elevations. Previously pitch was always 0, causing tracers to shoot horizontally regardless of target height.
This commit is contained in:
parent
95a579a3e6
commit
299397203f
1 changed files with 9 additions and 5 deletions
|
|
@ -586,13 +586,17 @@ class BotManager(zone: Zone) extends Actor {
|
||||||
private def startFiring(botState: BotState, target: Player): Unit = {
|
private def startFiring(botState: BotState, target: Player): Unit = {
|
||||||
val player = botState.player
|
val player = botState.player
|
||||||
|
|
||||||
// Calculate yaw to face target
|
// Calculate yaw (horizontal) and pitch (vertical) to face target
|
||||||
val dx = target.Position.x - player.Position.x
|
val dx = target.Position.x - player.Position.x
|
||||||
val dy = target.Position.y - player.Position.y
|
val dy = target.Position.y - player.Position.y
|
||||||
|
val dz = target.Position.z - player.Position.z // Height difference
|
||||||
|
val horizontalDist = math.sqrt(dx * dx + dy * dy)
|
||||||
|
|
||||||
val targetYaw = math.toDegrees(math.atan2(dx, dy)).toFloat
|
val targetYaw = math.toDegrees(math.atan2(dx, dy)).toFloat
|
||||||
|
val targetPitch = math.toDegrees(math.atan2(dz, horizontalDist)).toFloat
|
||||||
|
|
||||||
// Update bot's orientation to face target
|
// Update bot's orientation to face target
|
||||||
player.Orientation = Vector3(0, 0, targetYaw)
|
player.Orientation = Vector3(0, targetPitch, targetYaw)
|
||||||
|
|
||||||
// Broadcast PlayerState with correct orientation BEFORE fire state
|
// Broadcast PlayerState with correct orientation BEFORE fire state
|
||||||
// This ensures client has correct facing when fire state arrives
|
// This ensures client has correct facing when fire state arrives
|
||||||
|
|
@ -603,9 +607,9 @@ class BotManager(zone: Zone) extends Actor {
|
||||||
player.GUID,
|
player.GUID,
|
||||||
player.Position,
|
player.Position,
|
||||||
player.Velocity,
|
player.Velocity,
|
||||||
targetYaw, // facingYaw - body direction
|
targetYaw, // facingYaw - body direction (horizontal)
|
||||||
0f, // facingPitch
|
targetPitch, // facingPitch - vertical aim angle
|
||||||
0f, // facingYawUpper - relative to body, 0 = looking straight
|
0f, // facingYawUpper - relative to body, 0 = looking straight
|
||||||
timestamp,
|
timestamp,
|
||||||
is_crouching = false,
|
is_crouching = false,
|
||||||
is_jumping = false,
|
is_jumping = false,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue