restrict auto-aim to 90 degrees

This commit is contained in:
Lephenixnoir 2022-06-25 17:49:52 +01:00
parent 05ba2b75c4
commit 22fb1c55d0
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
3 changed files with 19 additions and 4 deletions

View File

@ -47,6 +47,18 @@ vec2 vec_rotate_m30(vec2 v)
-v.x / 2 + fmul(fix(0.866), v.y) };
}
vec2 vec_rotate_45(vec2 v)
{
return (vec2){ fmul(fix(0.707), v.x) - fmul(fix(0.707), v.y),
fmul(fix(0.707), v.x) + fmul(fix(0.707), v.y) };
}
vec2 vec_rotate_m45(vec2 v)
{
return (vec2){ fmul(fix(0.707), v.x) + fmul(fix(0.707), v.y),
-fmul(fix(0.707), v.x) + fmul(fix(0.707), v.y) };
}
//---
// Rect operations
//---

View File

@ -58,10 +58,11 @@ irect rect_f2i(rect);
/* Dot product. */
fixed_t vec_dot(vec2, vec2);
/* Rotate a vector by 30° */
/* Rotate a vector by some constants */
vec2 vec_rotate_30(vec2);
/* Rotate a vector by -30° */
vec2 vec_rotate_m30(vec2);
vec2 vec_rotate_45(vec2);
vec2 vec_rotate_m45(vec2);
//---
// Point operations

View File

@ -344,14 +344,16 @@ vec2 pathfinding_autoaim(game_t const *game, entity_t *src, map_t const *map)
continue;
vec2 relpos = { p->x - src_pos.x, p->y - src_pos.y };
if(vec_dot(relpos, vec_rotate_30(src_facing)) < 0)
if(vec_dot(relpos, vec_rotate_45(src_facing)) < 0)
continue;
if(vec_dot(relpos, vec_rotate_m30(src_facing)) < 0)
if(vec_dot(relpos, vec_rotate_m45(src_facing)) < 0)
continue;
fixed_t dist2 = fmul(relpos.x, relpos.x) + fmul(relpos.y, relpos.y);
if(dist2 < best_dist2 || best_dist2 < 0) {
/* TODO: Prune based on raycasts */
(void)map;
best_dist2 = dist2;
current_best_dir = fnormalize(relpos);
}