jwunderl / arcade-tilemap-a-star

a star implementation for tilemaps in pxt-arcade ---beta
https://jwunderl.github.io/arcade-tilemap-a-star/
MIT License
6 stars 7 forks source link

WIP on moving sprites to the path correctly #3

Closed darzu closed 4 years ago

darzu commented 4 years ago

Test project: https://makecode.com/_eCTHYFMLqg3Y

future TODO: transition sprite gently to middle of first tile

this PR TODO:

Current state: 2020-05-14 20 02 49

Notice how they move to the path but don't follow it once they get there

darzu commented 4 years ago

2020-05-14 20 12 55

Working pretty well!

darzu commented 4 years ago

Looks good, other comment can be fixed in a separate change if you want / is a bit of an edge case

I'm going to try your approach and run a stress test and see how much we can handle

darzu commented 4 years ago

Updated to use Dijkstra's to get to the path:

2020-05-15 16 17 20

darzu commented 4 years ago

Hmm there's definitely some buggy behavior going on that I need to look into: 2020-05-15 16 48 34

darzu commented 4 years ago

Yeah, it's definitely buggy with the removing and add even with the run-in-parallel code. I'll see what I can do

darzu commented 4 years ago

Some adversarial routing with probably a couple hundred sprites active: 2020-05-15 19 20 03

Not too shabby! A couple seconds delay on my macbook pro. Unsure how this will perform on hardware.

darzu commented 4 years ago

Alright I made a pass over the path following logic and made a few minor improvements:

  1. Instead of teleporting to the start of the path, I just set the velocity to face that title
  2. Instead of keeping a seperate "to remove" list, I enumerate the sprites backwards so that I can do "removeAt" and "push" without affecting the worklist. This makes it so that I don't need the "run in parallel" code anymore and also fixed some bugs around sprites not resuming pathing properly if there are lots of path switches.
  3. I use vector math instead of atan2 + cos + sin to set direction; sqrt is much faster than trig functions generally
  4. Fixed a bug where we weren't setting the a new "on end" callback correctly

I think things basically work well now: 2020-05-22 10 34 48

There are some weird interactions when sprites are place inside of walls (e.g. placing a tower on them). Sprites don't get back onto the path. But I'm not sure the path following logic can do too much about that.