mirror of
https://github.com/RYDE-WORK/ballistica.git
synced 2026-02-05 06:53:18 +08:00
Temp solution for bots' AI
This commit is contained in:
parent
e109c51bf7
commit
ac7d79c7bf
@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import math
|
||||||
import random
|
import random
|
||||||
import weakref
|
import weakref
|
||||||
from typing import TYPE_CHECKING
|
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_COLOR = (1.0, 0.2, 0.1)
|
||||||
PRO_BOT_HIGHLIGHT = (0.6, 0.1, 0.05)
|
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:
|
class SpazBotPunchedMessage:
|
||||||
"""A message saying a ba.SpazBot got punched.
|
"""A message saying a ba.SpazBot got punched.
|
||||||
@ -192,7 +200,7 @@ class SpazBot(basespaz.Spaz):
|
|||||||
closest = None
|
closest = None
|
||||||
assert self._player_pts is not None
|
assert self._player_pts is not None
|
||||||
for plpt, plvel in self._player_pts:
|
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
|
# Ignore player-points that are significantly below the bot
|
||||||
# (keeps bots from following players off cliffs).
|
# (keeps bots from following players off cliffs).
|
||||||
@ -324,7 +332,7 @@ class SpazBot(basespaz.Spaz):
|
|||||||
target_vel * dist_raw * 0.3 * self._lead_amount)
|
target_vel * dist_raw * 0.3 * self._lead_amount)
|
||||||
|
|
||||||
diff = (target_pt - our_pos)
|
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()
|
to_target = diff.normalized()
|
||||||
|
|
||||||
if self._mode == 'throw':
|
if self._mode == 'throw':
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user