EnemyAI Pseudocode

Wasn’t sure what we were supposed to share with psuedocode but here’s my stab at it.

void Enemy::tick(float deltaTime)
{
    // Vector2 toTarget = worldPos - target->worldPos
    // toTarget = Normalize toTarget
    // to Target = toTarget * speed
    // worldPos = toTarget + worldPos
    if (target != nullptr ) screenPos = Vector2Subtract(worldPos, target->getWorldPos());
    BaseCharacter::tick(deltaTime);

}
3 Likes

Looks good :+1:

It is a good approach, you are setting a useful conditional to avoid errors. With that said, if the target is null you can add a debug message so you can work on it. Also, you can use the DrawText function to draw the substraction result (using a C-Style or std string which is explained in one of the last lessons).

Good job there

Privacy & Terms