flowtsohg / mdx-m3-viewer

A WebGL viewer for MDX and M3 files used by the games Warcraft 3 and Starcraft 2 respectively.
MIT License
132 stars 47 forks source link

How do you get an arbitrary model to walk around with animation? #70

Closed arcman7 closed 3 years ago

arcman7 commented 3 years ago

Demo video

You can see in this video, the sheep models just float from one location to the next without any sort of walking animation. The code that updates their positions looks like this:

function walkSheepToNewLocations(directions, delta) {
      for (let i = 0; i < sEnv.num_sheep; i++) {
          sheepModelInstances[i].setSequence(sheepWalkSeq, true) // using that boolean extra arg introduced in PR https://github.com/flowtsohg/mdx-m3-viewer/pull/69
          sheepModelInstances[i].move([directions[i][0] * delta, directions[i][1] * delta, 0] )
      }
}

What's weird is I never came across this issue when animating a single Grunt model walking. I would merely set the sequence to the walk value and then start calling gruntModelInstance.move([delta_x, delta_y, 0]).

With the sheep it doesn't matter if I remove sheepModelInstances[i].setSequence(sheepWalkSeq, true) from the for-loop or not, they still just float around.

arcman7 commented 3 years ago

Okay, I understand now what you're saying regarding the fps. Thank you for the clarification there.

As for the animations, I noticed the model instances are having their animation sequence being reset by something; probably similar to what was happening here https://github.com/flowtsohg/mdx-m3-viewer/pull/69/files#

Did you revert any of that stuff? I don't see how I can set an animation sequence on a model instance and have it be preserved throughout the map update calls right now.

flowtsohg commented 3 years ago

Look a couple of message up where I added WidgetState.IDLE and WidgetState.WALK :P

arcman7 commented 3 years ago

For example if you have your sheep in map.units, you can do sheep.state = WidgetState.WALK (from widget.ts) and it won't run the stand animations.

😅 Omg. I feel dumb. It's been too long! I'm just surprised I didn't immediately change my code to use those changes.