16 AICharacter::AICharacter(std::string model_name,
NodePath model_np,
double mass,
double movt_force,
double max_force) {
18 _ai_char_np = model_np;
21 _max_force = max_force;
22 _movt_force = movt_force;
24 _velocity = LVecBase3(0.0, 0.0, 0.0);
25 _steering_force = LVecBase3(0.0, 0.0, 0.0);
30 _steering->_ai_char =
this;
35 AICharacter::~AICharacter() {
36 nassertv(_world ==
nullptr);
46 if (!_steering->
is_off(_steering->_none)) {
47 LVecBase3 old_pos = _ai_char_np.
get_pos();
49 LVecBase3 acceleration = steering_force / _mass;
51 _velocity = acceleration;
53 LVecBase3 direction = _steering->_steering_force;
54 direction.normalize();
56 _ai_char_np.set_pos(old_pos + _velocity) ;
58 if (steering_force.length() > 0) {
59 _ai_char_np.
look_at(old_pos + (direction * 5));
60 _ai_char_np.set_h(_ai_char_np.get_h() + 180);
61 _ai_char_np.set_p(-_ai_char_np.get_p());
62 _ai_char_np.set_r(-_ai_char_np.get_r());
65 _steering->_steering_force = LVecBase3(0.0, 0.0, 0.0);
66 _steering->_seek_force = LVecBase3(0.0, 0.0, 0.0);
67 _steering->_flee_force = LVecBase3(0.0, 0.0, 0.0);
68 _steering->_pursue_force = LVecBase3(0.0, 0.0, 0.0);
69 _steering->_evade_force = LVecBase3(0.0, 0.0, 0.0);
70 _steering->_arrival_force = LVecBase3(0.0, 0.0, 0.0);
71 _steering->_flock_force = LVecBase3(0.0, 0.0, 0.0);
72 _steering->_wander_force = LVecBase3(0.0, 0.0, 0.0);
76 LVecBase3 AICharacter::get_velocity() {
80 void AICharacter::set_velocity(LVecBase3 velocity) {
84 double AICharacter::get_mass() {
88 void AICharacter::set_mass(
double m) {
92 double AICharacter::get_max_force() {
96 void AICharacter::set_max_force(
double max_force) {
97 _max_force = max_force;
100 NodePath AICharacter::get_node_path() {
104 void AICharacter::set_node_path(
NodePath np) {
112 void AICharacter::set_char_render(
NodePath render) {
113 _window_render = render;
116 NodePath AICharacter::get_char_render() {
117 return _window_render;
120 void AICharacter::set_pf_guide(
bool pf_guide) {
121 _pf_guide = pf_guide;
LVecBase3 calculate_prioritized()
This function updates the main steering force for the ai character using the accumulate function and ...
bool is_off(_behavior_type bt)
This function returns true if an aiBehavior is off.
This class implements all the steering behaviors of the AI framework, such as seek,...
LPoint3 get_pos() const
Retrieves the translation component of the transform.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
void update()
Each character's update will update its AI and physics based on his resultant steering force.
void look_at(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z)
Sets the transform on this NodePath so that it rotates to face the indicated point in space.