Gameplay/Systems Programmer
Mandragora is the name of the first game project we did at FutureGames, and my first game project ever. My responsibilities in the project were pretty much everything pertaining to the little creatures scurrying about. I also made the music for the game.
This project was created as part of the school curriculum.
The AI in Mandragora is quite simple. The creatures are kind of like cars. They have an acceleration time, a deceleration time, and a turn radius.
It is a finite state machine with the core states being SCURRY and IDLE. In SCURRY mode, a random point is chosen within a view radius, and it is ensured that the point is both vacant and reachable in a straight line. Then, it simply accelerates towards it.
While it is going towards its target, it continuously checks that the path to the target is clear. If it is not, it finds a new target.
This results in the emergent behavior of appearing to specifically avoid the player. Because many points behind are not clear, and the line to them are easily broken by the player, it will prefer targets that are away from the player. As a result the AI looks quite natural in spite of being incredibly simple.
Once the creatures approaches the target, it will go into IDLE for a randomized duration.
The camera in Mandragora uses simple trigonometry to keep both players in view. The basic version forces the angle to be constant between the players by moving the camera back and forth, and the more advanced version softens this a bit by allowing a greater angle when the players go further away from each other.
Finally, the camera is constantly lerped between its current position and its target position.
The result is a smooth, and consistent camera that allows for camera shake.
The basic math is essentially the following:
Where is the target offset along the view angle from the center of the two players, and are the positions of the two players. I'm simply calculating the distance between them. is the angle of the view vector from the ground, and
is the user defined angle that the players should be at from the center of the screen.
To adapt this for more players, the term for the distance between the players is replaced by the max distance from the center of the screen by any of the players