mirror of
https://github.com/RYDE-WORK/ballistica.git
synced 2026-01-25 00:13:27 +08:00
Temp solution for bots' AI
This commit is contained in:
parent
e109c51bf7
commit
ac7d79c7bf
@ -23,6 +23,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import math
|
||||
import random
|
||||
import weakref
|
||||
from typing import TYPE_CHECKING
|
||||
@ -41,6 +42,13 @@ DEFAULT_BOT_HIGHLIGHT = (0.1, 0.3, 0.1)
|
||||
PRO_BOT_COLOR = (1.0, 0.2, 0.1)
|
||||
PRO_BOT_HIGHLIGHT = (0.6, 0.1, 0.05)
|
||||
|
||||
def _my_vec3_dist(vec1: Tuple[float], vec2: Tuple[float]) -> float:
|
||||
# FIXME - this solution works,
|
||||
xlen = vec1[0] - vec2[0]
|
||||
ylen = vec1[1] - vec2[1]
|
||||
zlen = vec1[2] - vec2[2]
|
||||
xylen = math.sqrt(xlen**2 + ylen**2)
|
||||
return math.sqrt(xylen**2 + zlen**2)
|
||||
|
||||
class SpazBotPunchedMessage:
|
||||
"""A message saying a ba.SpazBot got punched.
|
||||
@ -192,7 +200,7 @@ class SpazBot(basespaz.Spaz):
|
||||
closest = None
|
||||
assert self._player_pts is not None
|
||||
for plpt, plvel in self._player_pts:
|
||||
dist = (plpt - botpt).length()
|
||||
dist = _my_vec3_dist((plpt.x, plpt.y, plpt.z), (botpt.x, botpt.y, botpt.z))
|
||||
|
||||
# Ignore player-points that are significantly below the bot
|
||||
# (keeps bots from following players off cliffs).
|
||||
@ -208,7 +216,7 @@ class SpazBot(basespaz.Spaz):
|
||||
ba.Vec3(closest_vel[0], closest_vel[1], closest_vel[2]))
|
||||
return None, None
|
||||
|
||||
def set_player_points(self, pts: List[Tuple[ba.Vec3, ba.Vec3]]) -> None:
|
||||
def set_player_points(self, pts: List[Tuple[ba.Vec3, ba.Vec3]]) -> None:
|
||||
"""Provide the spaz-bot with the locations of its enemies."""
|
||||
self._player_pts = pts
|
||||
|
||||
@ -324,7 +332,7 @@ class SpazBot(basespaz.Spaz):
|
||||
target_vel * dist_raw * 0.3 * self._lead_amount)
|
||||
|
||||
diff = (target_pt - our_pos)
|
||||
dist = diff.length()
|
||||
dist = _my_vec3_dist((target_pt.x, target_pt.y, target_pt.z), (our_pos.x, our_pos.y, our_pos.z))
|
||||
to_target = diff.normalized()
|
||||
|
||||
if self._mode == 'throw':
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user