This week, I worked on simple agent rendering: Rendering an
agent as a simple circle.
I also had to implement a Matrix, in which I had to
implement different functions such as
·
Translate
·
Rotate
·
Scale
·
Transform
This really helped with my 3-D math skills as I finally
understood how to create, store and operate the above properties on a game
object.
After that, I worked on behaviors:
Seek
Given a target point, the agent will try to move towards
that point.
First, we calculate the direction we need to move in by
subtracting our position from the target position, and normalizing it:
Vec2 direction = Vec2::Normalize(targetPosition - mpAgent->GetPosition());
We then calculate the velocity required by multiplying that
by the max possible velocity of the agent:
Vec2 desiredVelocity = direction * mpAgent->GetMaxSpeed();
Then the force required to get to that velocity would be the
difference between that and the current velocity:
Vec2 force = desiredVelocity - mpAgent->GetVelocity();
Flee
Flee is similar to Seek, except that the agent will move
away from the target point.
First, we calculate the direction we need to move in by
subtracting target position from our position, and normalizing it:
Vec2 direction = Vec2::Normalize(mpAgent->GetPosition() - targetPosition);
We then calculate the velocity required by multiplying that
by the max possible velocity of the agent:
Vec2 desiredVelocity = direction * mpAgent->GetMaxSpeed();
Then the force required to get to that velocity would be the
difference between that and the current velocity:
Vec2 force = desiredVelocity - mpAgent->GetVelocity();
I will continue to implement more steering patterns.
Comments