From fa6f9b72b359f346b57fb5e860c58acec25d3e9c Mon Sep 17 00:00:00 2001 From: Tom Date: Wed, 23 Sep 2020 15:23:47 -0700 Subject: [PATCH] Get Ascend* movements working reliably --- bot/path/movement.go | 2 +- bot/path/path.go | 19 +++++++++++++++---- bot/phy/phy.go | 15 +++++---------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/bot/path/movement.go b/bot/path/movement.go index dc37b00..dd1a0b7 100644 --- a/bot/path/movement.go +++ b/bot/path/movement.go @@ -123,7 +123,7 @@ func (m Movement) BaseCost() float64 { case TraverseNorth, TraverseSouth, TraverseEast, TraverseWest: return 1 case TraverseNorthWest, TraverseNorthEast, TraverseSouthWest, TraverseSouthEast: - return 1.5 + return 1.25 case DropNorth, DropSouth, DropEast, DropWest: return 2 diff --git a/bot/path/path.go b/bot/path/path.go index 06c39fa..841c915 100644 --- a/bot/path/path.go +++ b/bot/path/path.go @@ -8,6 +8,11 @@ import ( "github.com/beefsack/go-astar" ) +// Point represents a point in 3D space. +type Point struct { + X, Y, Z float64 +} + type V3 struct { X, Y, Z int } @@ -62,7 +67,7 @@ func (t Tile) PathEstimatedCost(to astar.Pather) float64 { func (t Tile) PathNeighbors() []astar.Pather { possibles := make([]astar.Pather, 0, 8) - if t.PathEstimatedCost(Tile{Pos: t.Nav.Start}) > 1200 { + if c := t.PathEstimatedCost(Tile{Pos: t.Nav.Start}); c > 8000 { return nil } @@ -88,9 +93,9 @@ func (t Tile) PathNeighbors() []astar.Pather { return possibles } -func (t Tile) Inputs(dX, dY, dZ float64) Inputs { +func (t Tile) Inputs(deltaPos, vel Point) Inputs { // Sufficient for simple movements. - at := math.Atan2(-dX, -dZ) + at := math.Atan2(-deltaPos.X, -deltaPos.Z) out := Inputs{ ThrottleX: math.Sin(at), ThrottleZ: math.Cos(at), @@ -98,7 +103,13 @@ func (t Tile) Inputs(dX, dY, dZ float64) Inputs { switch t.Movement { case AscendNorth, AscendSouth, AscendEast, AscendWest: - out.Jump = math.Sqrt(dX*dX+dZ*dZ) < 1.75 + dist2 := math.Sqrt(deltaPos.X*deltaPos.X + deltaPos.Z*deltaPos.Z) + out.Jump = dist2 < 1.75 && deltaPos.Y < -0.81 + + // Turn off the throttle if we get stuck on the jump. + if dist2 < 1 && deltaPos.Y < 0 && vel.Y == 0 { + out.ThrottleX, out.ThrottleZ = 0, 0 + } out.Yaw = 0 } return out diff --git a/bot/phy/phy.go b/bot/phy/phy.go index 6953f14..40ac58d 100644 --- a/bot/phy/phy.go +++ b/bot/phy/phy.go @@ -36,16 +36,11 @@ type World interface { // Surrounds represents the blocks surrounding the player (Y, Z, X). type Surrounds []AABB -// Point represents a point in 3D space. -type Point struct { - X, Y, Z float64 -} - // State tracks physics state. type State struct { // player state. - Pos Point - Vel Point + Pos path.Point + Vel path.Point Yaw, Pitch float64 lastJump uint32 @@ -61,9 +56,9 @@ type State struct { } func (s *State) ServerPositionUpdate(player player.Pos, w World) error { - s.Pos = Point{X: player.X, Y: player.Y, Z: player.Z} + s.Pos = path.Point{X: player.X, Y: player.Y, Z: player.Z} s.Yaw, s.Pitch = float64(player.Yaw), float64(player.Pitch) - s.Vel = Point{} + s.Vel = path.Point{} s.onGround, s.collision.vertical, s.collision.horizontal = false, false, false s.Run = true return nil @@ -202,7 +197,7 @@ func (s *State) tickVelocity(input path.Inputs, w World) { s.Vel.Z *= inertia } -func (s *State) computeCollision(bb, query AABB, w World) (outBB AABB, outVel Point) { +func (s *State) computeCollision(bb, query AABB, w World) (outBB AABB, outVel path.Point) { surroundings := s.surroundings(query, w) outVel = s.Vel