Mugen87 / yuka

JavaScript library for developing Game AI.
https://mugen87.github.io/yuka/
MIT License
1.1k stars 90 forks source link

Question: Best Practices #60

Closed arcman77 closed 2 years ago

arcman77 commented 2 years ago

In a given state, one that controls behavior:

Where should changes to the agents steering behavior go?

export class FooState extends YUKA.State {
  constructor() {}
  enter(agent) { 
    // Should this go here?
     agent.steering.behaviors[0].active = false
     agent.steering.behvariors[1].active = true
  }

  execute(agent) {
      // OR should this go here?
     agent.steering.behaviors[0].active = false
     agent.steering.behvariors[1].active = true
  }
}
Mugen87 commented 2 years ago

Such code is usually placed in enter(). enter() is executed only a single time a state becomes active and thus an ideal spot for setting up the game entity (e.g. with new steering behaviors).

arcman77 commented 2 years ago

Thank you!