Created
June 3, 2014 04:31
-
-
Save thetooth/2efe61ab9e16afee62dc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void Path::Follow(AI &ai){ | |
| float nx, ny; | |
| if (!ai.casual && index < nodeList.size() && index < 4){ | |
| auto node = (int)nodeList[index]; | |
| ny = node / solver->mapWidth; | |
| nx = node - ny * solver->mapWidth; | |
| nx *= PATH_DIVISOR; | |
| ny *= PATH_DIVISOR; | |
| }else{ | |
| ai.casual = true; | |
| nx = target.x; | |
| ny = target.y; | |
| } | |
| float dx = nx - ai.pos.x; | |
| float dy = ny - ai.pos.y; | |
| auto attack = atan2(dy, dx); | |
| ai.vel.x = cos(attack) * ai.speed; | |
| ai.vel.y = sin(attack) * ai.speed; | |
| if (std::abs(dx) < 1.0 && std::abs(dy) < 1.0){ | |
| ai.vel.x = 0.0; ai.vel.y = 0.0; | |
| if (!ai.casual){ | |
| ai.pos.x = nx; ai.pos.y = ny; | |
| index++; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment