Changeset 10667 in orxonox.OLD for branches/vs-enhencements/src/world_entities/npcs
- Timestamp:
- Jun 1, 2007, 12:01:20 PM (18 years ago)
- Location:
- branches/vs-enhencements/src/world_entities/npcs
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/vs-enhencements/src/world_entities/npcs/actionbox_enemy.cc
r10662 r10667 41 41 this->dPitch = 0.0; 42 42 43 this->maxSpeed = 10;43 this->maxSpeed = 30; 44 44 this->acceleration = 3; 45 45 this->speed = 0; 46 46 47 this->onEscape = false; 48 47 49 if ( root ) 48 50 this->loadParams( root ); … … 60 62 void ActionboxEnemy::tick( float dt ) 61 63 { 64 this->bFire = false; 65 66 if ( !State::getPlayer() || !State::getPlayer()->getPlayable() ) 67 return; 68 69 Vector playerDir = State::getPlayer()->getPlayable()->getAbsDir().apply( Vector(1, 0, 0) ); 70 Vector dist = this->getAbsCoor() - State::getPlayer()->getPlayable()->getAbsCoor(); 71 72 bool behindPlayer = playerDir.dot( dist ) < 0; 73 74 if ( behindPlayer ) 75 return; 76 62 77 myDir = this->getAbsDir(); 63 78 myCoor = this->getAbsCoor(); … … 73 88 qPitch = Quaternion( pitch, Vector( 1, 0, 0 ) ); 74 89 75 moveTowardsBox( NULL, dt );76 77 90 if ( isActive && State::getActionBox() ) 78 91 { … … 85 98 { 86 99 moveTowardsBox( box, dt ); 100 onEscape = false; 87 101 } 88 102 } … … 96 110 void ActionboxEnemy::attackPlayer( ActionBox * box, float dt ) 97 111 { 98 } 99 100 void ActionboxEnemy::moveTowardsBox( ActionBox * box, float dt ) 101 { 102 //Vector targetPos = State::getPlayer()->getPlayable()->getAbsCoor(); 103 static float time = 0; 104 time += dt; 105 Vector targetPos = State::getPlayer()->getPlayable()->getAbsCoor() + State::getPlayer()->getPlayable()->getAbsDir().apply(Vector(1, 0, 0))*50*(1.5 + sin(time/5)); 106 Vector targetDir = targetPos - myCoor; 107 112 if ( !State::getPlayer() || !State::getPlayer()->getPlayable() || !box ) 113 return; 114 115 float distance = (State::getPlayer()->getPlayable()->getAbsCoor() - getAbsCoor() ).len(); 116 117 if ( distance > box->getDepth()/4.0 && !onEscape ) 118 { 119 Vector targetPos = State::getPlayer()->getPlayable()->getAbsCoor(); 120 Vector targetDir = State::getPlayer()->getPlayable()->getAbsCoor()-this->getAbsCoor(); 121 moveTowards( targetPos, targetDir, dt ); 122 if ( this->getAbsDir().apply( Vector(1, 0, 0) ).dot(targetDir) > 0.9 ) 123 { 124 this->bFire = true; 125 PRINTF(0)("FIRE\n"); 126 } 127 } 128 else 129 { 130 if ( !onEscape ) 131 { 132 Vector ds = this->getAbsCoor() - State::getPlayer()->getPlayable()->getAbsCoor(); 133 float projy = box->getAbsDir().apply( Vector(0, 1, 0) ).dot( ds ); 134 float projz = box->getAbsDir().apply( Vector(0, 0, 1) ).dot( ds ); 135 this->escapePoint = Vector( 0, projy, projz ); 136 this->escapePoint.normalize(); 137 this->escapePoint*= 2*box->getWidth_2(); 138 PRINTF(0)("ESCAPE\n"); 139 } 140 onEscape = true; 141 142 Vector rEscapePoint = box->getAbsDir().apply(escapePoint); 143 Vector targetPos = State::getPlayer()->getPlayable()->getAbsCoor() + rEscapePoint; 144 Vector targetDir = State::getPlayer()->getPlayable()->getAbsCoor() + rEscapePoint - this->getAbsCoor(); 145 moveTowards( targetPos, targetDir, dt ); 146 } 147 } 148 149 void ActionboxEnemy::moveTowards( Vector targetPos, Vector targetDir, float dt ) 150 { 108 151 Quaternion cur = myDir; 109 152 Quaternion rx( dt, Vector( 0, 0, 1 ) ); … … 144 187 } 145 188 189 void ActionboxEnemy::moveTowardsBox( ActionBox * box, float dt ) 190 { 191 192 Vector targetPos = box->getAbsCoor() + box->getAbsDir().apply( Vector( 1, 0, 0 ) )*box->getDepth()*0.66f; 193 Vector targetDir = targetPos - myCoor; 194 195 moveTowards(targetPos, targetDir, dt); 196 } 197 146 198 void ActionboxEnemy::draw( ) const 147 199 { -
branches/vs-enhencements/src/world_entities/npcs/actionbox_enemy.h
r10662 r10667 33 33 Vector myCoor; 34 34 35 bool bFire; 36 37 Vector escapePoint; 38 bool onEscape; 39 35 40 void attackPlayer( ActionBox* box, float dt ); 36 41 void moveTowardsBox( ActionBox* box, float dt ); 42 void moveTowards( Vector targetPos, Vector targetDir, float dt ); 37 43 }; 38 44
Note: See TracChangeset
for help on using the changeset viewer.