Move to our own vector module instead of Panda3D

This commit is contained in:
2021-03-23 21:01:48 +00:00
parent 2fa3044acb
commit 0bdae1f775
3 changed files with 137 additions and 13 deletions

21
bot.py
View File

@@ -24,7 +24,7 @@ from minecraft.networking.packets import Packet, clientbound, serverbound
from protocol.managers import DataManager, ChunksManager, ChatManager, ChunkNotLoadedException
from munch import Munch
from panda3d.core import LPoint3f, LVector3f
from vector import Point3D, Vector3D
import game
importlib.reload(game)
@@ -41,9 +41,9 @@ importlib.reload(mcdata)
last_tick = time.time()
PITCH_ANGLE_DIR = LVector3f(x=0, y=1, z=0)
YAW_ANGLE_DIR = LVector3f(x=0, y=0, z=-1)
YAW_ANGLE_REF = LVector3f(x=0, y=1, z=0)
PITCH_ANGLE_DIR = Vector3D((0, 1, 0))
YAW_ANGLE_DIR = Vector3D((0, 0, -1))
YAW_ANGLE_REF = Vector3D((0, 1, 0))
YAW_LOOK_AHEAD = 4
@@ -105,7 +105,7 @@ def tick(global_state):
########## player physics ##########
if g.path and len(g.path):
target = LPoint3f(g.path[0])
target = Point3D(g.path[0])
target.x += 0.5
target.z += 0.5
@@ -158,11 +158,11 @@ def tick(global_state):
g.y_a = 0
if g.look_at:
look_at = LPoint3f(g.look_at)
look_at = Point3D(g.look_at)
elif g.path and len(g.path) > YAW_LOOK_AHEAD:
look_at = LPoint3f(g.path[YAW_LOOK_AHEAD])
look_at = Point3D(g.path[YAW_LOOK_AHEAD])
elif g.path and len(g.path):
look_at = LPoint3f(g.path[-1])
look_at = Point3D(g.path[-1])
else:
look_at = None
@@ -177,9 +177,10 @@ def tick(global_state):
target_pitch_d = target_pitch - g.pitch
g.pitch += utils.cap(target_pitch_d, 10)
# remove vertical component for yaw calculation
look_at_d.y = 0
# remove vertical component for yaw calculation
look_at_d.y = 0
if look_at_d.length() > 0.6:
target_yaw = look_at_d.normalized().signedAngleDeg(other=YAW_ANGLE_DIR, ref=YAW_ANGLE_REF)
target_yaw_d = target_yaw - g.yaw
target_yaw_d = (target_yaw_d + 180) % 360 - 180