big update
This commit is contained in:
11
game/ai.js
11
game/ai.js
@@ -30,11 +30,14 @@
|
||||
let hold = { throttle: 0, turn: 0, fire: false, fire2: false }, wait = 0, stuck = 0, unstick = 0, contact = 0, retreat = 0, wob = rand() * 6;
|
||||
const react = 0.32 - skill * 0.26; // seconds between decisions
|
||||
|
||||
function steer(me, tx, tz, speed = 1) {
|
||||
const want = Math.atan2(tz - me.z, tx - me.x), diff = wrap(want - me.a);
|
||||
// aim=true: orient so the weapon (which may sit on the back/side) faces the target, else aim the front
|
||||
function steer(me, tx, tz, speed = 1, aim = false) {
|
||||
const mA = aim ? (me.st.mountA || 0) : 0;
|
||||
const want = wrap(Math.atan2(tz - me.z, tx - me.x) - mA), diff = wrap(want - me.a);
|
||||
const turn = clamp(diff * 2.2, -1, 1);
|
||||
const ad = Math.abs(diff);
|
||||
const throttle = ad < 0.5 ? speed : ad < 1.4 ? speed * 0.45 : ad > 2.6 && Math.hypot(tx - me.x, tz - me.z) < 2 ? -0.6 : 0.1;
|
||||
const dir = Math.cos(mA) < -0.5 ? -1 : 1; // rear-mounted weapon: reverse to bring it onto the enemy
|
||||
const throttle = (ad < 0.5 ? speed : ad < 1.4 ? speed * 0.45 : ad > 2.6 && Math.hypot(tx - me.x, tz - me.z) < 2 ? -0.6 : 0.1) * dir;
|
||||
return { turn, throttle };
|
||||
}
|
||||
|
||||
@@ -64,7 +67,7 @@
|
||||
} else if (style === 'gunner' && t) { // face the enemy (fixed turret), hold the range
|
||||
tx = e.x; tz = e.z;
|
||||
}
|
||||
let cmd = steer(me, tx, tz, 0.75 + skill * 0.25);
|
||||
let cmd = steer(me, tx, tz, 0.75 + skill * 0.25, style !== 'pusher');
|
||||
// gunner too close: back off but keep the nose (and the turret) on the enemy
|
||||
if (style === 'gunner' && t && dist < ((t.type === 'flamer' || t.type === 'zapper') ? 1.4 : 2.8)) cmd = { turn: cmd.turn, throttle: -0.7 };
|
||||
|
||||
|
||||
Reference in New Issue
Block a user