restrict auto-aim to 90 degrees
This commit is contained in:
parent
05ba2b75c4
commit
22fb1c55d0
|
@ -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
|
||||
//---
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue